.


:




:

































 

 

 

 





PHP, SQL , Apache. FuelPHP[1].
PHP Storm[2].

. 15 22 .

 

15

 

16 , ,

17 , ,

18 , , ,

19

 

20 (, )

 

21 , ,

 

 

22 , ,

 

22 ( )

 

 

: HTML[3], CSS, Bootstrap 3.0, JavaScript ( Jquery[4]). 15 22.

 


- һ.

- .

- .


- .

- .

- .

- .

- .


1 http://fuelphp.com/

2 https://www.jetbrains.com/phpstorm/

3 https://ru.wikipedia.org/wiki/HTML

4 https://jquery.com/


Users.php

<?php

use Model\Operational\Suppliers;

use Model\Users;

use Model\Operational\Country;

use Model\System;

use Model\Reference\Subdivisions;

 

class Controller_Admin_Users extends Controller_Admin_Main {

public function before() {

parent::before();

Lang::load('users', 'users', Session::get('language', Config::get('language')), true, true);

$actions_data = array('section' => $this->section);

$this->template->topside = Presenter::forge('admin/topside');

$this->template->header = View::forge('admin/header', $this->data_header);

$this->template->topside->set('title', __('users.title'), false);

$this->template->actions = View::forge('actions.php', $actions_data);

}

 

public function action_list() {

$this->template->title = __('users.title');

$data['users'] = Users::getAll();

$data['roles'] = Users::getAllRoles();

$data['subdivisions'] = Subdivisions::getAll();

 

//

foreach ($data['users'] as $key => $value) {

$data['users'][$key]['subdivisions'] = Users::getUserSubdivisions($value['id']);

}

//print_r($data); die();

$this->template->content = View::forge('admin/users/list', $data);

 

}

 

//

public function action_create_user() {

$data['password'] = \Input::post('password');

$data['lastname'] = \Input::post('lastname');

$data['name'] = \Input::post('name');

$data['patronymic'] = \Input::post('patronymic');

$data['phone'] = \Input::post('phone');

$data['email'] = \Input::post('email');

$data['role_id'] = \Input::post('role_id');

$data['user_subdivisions'] = \Input::post('user_subdivisions');

 

if(empty($data['email'])) return json_encode('1');

if(empty($data['password'])) return json_encode('2');

if(empty($data['role_id'])) return json_encode('3');

 

$res = Users::addUser($data);

if($res){

//

$data['user_id'] = $this->current_user['id'];

$data['event_type'] = '';

$data['source'] = ' action_create_user, users.php';

$data['details'] = ' ';

System::setlog($data);

return json_encode("OK");

}else{

return json_encode("0");

}

}

 

//

public function action_edit_user() {

$data['lastname'] = \Input::post('lastname');

$data['name'] = \Input::post('name');

$data['patronymic'] = \Input::post('patronymic');

$data['phone'] = \Input::post('phone');

$data['email'] = \Input::post('email');

$data['role_id'] = \Input::post('role_id');

$data['password'] = \Input::post('password');

$data['id'] = \Input::post('id');

$data['edit_user_subdivisions'] = \Input::post('edit_user_subdivisions');

 

Users::ajax_edit_user($data);

//

$data['user_id'] = $this->current_user['id'];

$data['event_type'] = '';

$data['source'] = ' action_edit_user, users.php';

$data['details'] = ' - '.$data['id'];

System::setlog($data);

return json_encode("OK");

}

 

//

public function action_delete_user() {

$data['id'] = \Input::post('id');

if(empty($data['id'])) return json_encode('1');

Users::deleteUser($data['id']);

//

$data['user_id'] = $this->current_user['id'];

$data['event_type'] = '';

$data['source'] = ' action_edit_user, users.php';

$data['details'] = ' - '.$data['id'];

System::setlog($data);

return json_encode("OK");

}

 

 

/**

* ( )

* @return $content

*/

public function action_getUserInfoAJAX()

{

$user_id = Input::post('id', '');

$supplier_id = Input::post('supplier_id', '');

$db_id = Suppliers::getDBIDBySupplierId($supplier_id);

 

$user = Users::findUserInfo($user_id, $db_id);

$result = View::forge('admin/users/ajax/_showinfo', array('user' => $user[0]));

return $result;

}

 

public function action_individuals()

{

$this->template->title = __('users.title_individuals');

$this->template->topside->set('title', __('users.title_individuals'), false);

$this->template->content = ViewModel::forge('admin/users', 'contragentsindividuals');

 

$this->template->content->set('countries', Country::find('all'));

$this->template->content->set('suppliers', Suppliers::getSuppliersList());

 

$this->template->content->set('email', trim(Input::get('email_input', '')));

$this->template->content->set('guid', trim(Input::get('guid_input', '')));

$this->template->content->set('mode', trim(Input::get('mode', 'suppliers')));

 

$this->template->content->set('selected_country', $checkData['selected_country'] = (int) trim(Input::get('selected_country', '')));

$this->template->content->set('parent', $checkData['parent'] = (int) trim(Input::get('parent_input', '')));

$this->template->content->set('created_by', $checkData['created_by'] = (int) trim(Input::get('created_by_input', '')));

$this->template->content->set('input_supplier_id', $checkData['input_supplier_id'] = $input_supplier_id = (int) trim(Input::get('input_supplier_id', '')));

$this->template->content->set('supplier_id', $checkData['supplier_id'] = (int) trim(Input::get('supplier_id', '')));

$this->template->content->set('db_id', $checkData['db_id'] = (int) trim(Input::get('db_id', '')));

 

 

$this->template->content->set('active', $checkData['active'] = Input::get('active', ''));

$this->template->content->set('order_by', $checkData['order_by'] = Input::get('order_by', ''));

 

$this->template->content->set('page', $this->page);

$this->template->content->set('onpage', $this->onpage);

 

$val = Validation::forge('search_user');

 

$val->add('login','login')

->add_rule('min_length',2);

 

$val->add('email')

->add_rule('valid_email')

->add_rule('max_length',255);

 

$val->add('fname','fname')

->add_rule('min_length',1);

 

$val->add('sname','sname')

->add_rule('min_length',1);

 

$val->add('lname','lname')

->add_rule('min_length',1);

 

$val->add('supplier_id','supplier_id')

->add_rule('numeric_min', 0);

 

$val->add('db_id','db_id')

->add_rule('numeric_min', 0);

 

//

$val->set_message('required', ':label '. __('users.error.required'). '!');

$val->set_message('min_length', ':label '. __('users.error.min_length'). '!');

$val->set_message('max_length', ':label '. __('users.error.max_length'). '!');

$val->set_message('valid_email', __('users.error.valid_email'). ':label!');

$val->set_message('numeric_min', ':label '. __('users.error.numeric_min'). '!');

 

$error = '';

if(!$val->run($checkData))

{

$error = current($val->error());

}

$this->template->content->set('error', $error);

$this->template->content->set('buttons', $this->data['buttons']);

}

 

public function action_delete()

{

$user_id = Input::post('user_id', 0);

return Users::deleteUser($user_id);

}

 

public function action_setactivestatus()

{

$user_id = Input::post('user_id', 0);

$status = Input::post('status', '');

return Users::setActiveStatus($user_id, $status);

}

 

public function action_edit($id)

{

$this->template->title = __('users.edit_title');

$this->template->topside->set('title', __('users.edit_title'), false);

$data = array();

$data['user_id'] = $id;

$this->template->content = View::forge('admin/users/edit', $data);

}

 

public function action_edit_supplier_contractor($id, $supplier_id)

{

$this->template->title = __('users.edit_supplier_contractor_title');

$this->template->topside->set('title', __('users.edit_supplier_contractor_title'), false);

$data = array();

$data['contractor_id'] = $id;

$data['db_id'] = Suppliers::getDBIDBySupplierId($supplier_id);

$this->template->content = View::forge('admin/contragentsindividuals/editsuppliercontractor', $data);

}

 

/**

* -

* @return bool

*/

public function action_delete_supplier_contractor()

{

$contractor_id = Input::post('contractor_id', 0);

$supplier_id = Input::post('supplier_id', 0);

$db_id = Suppliers::getDBIDBySupplierId($supplier_id);

return Users::deleteSupplierContractor($db_id, $contractor_id);

}

public function action_edit_user_contractor($id)

{

$this->template->title = __('users.edit_user_contractor_title');

$this->template->topside->set('title', __('users.edit_user_contractor_title'), false);

$data = array();

$data['contractor_id'] = $id;

$this->template->content = View::forge('admin/contragentsindividuals/editusercontractor', $data);

}

public function action_delete_user_contractor()

{

$contractor_id = Input::post('contractor_id', 0);

$supplier_id = Input::post('supplier_id', 0);

$db_id = Suppliers::getDBIDBySupplierId($supplier_id);

return Users::deleteUserContractor($db_id, $contractor_id);

}

 

public function post_getbysupplier()

{

if((int)Input::post('group_id') >= 0)

{

return json_encode(Users::getByGroupId(Input::post('group_id'), Input::post('supplier_id'), Input::post('db_id')));

}

return json_encode(Users::getBySupplierId(Input::post('supplier_id'), Input::post('db_id')));

}

public function post_getbygroupid()

{

return json_encode(Users::getByGroupId(Input::post('group_id'), Input::post('supplier_id'), Input::post('db_id')));

}

public function post_search()

{

return json_encode(Users::search(Input::post('text')));

}

}

 

List.php

<div class="container-fluid subline">

</div>

 

<div class="container-fluid">

<table class="table-objects table table-striped table-bordered table-hover">

<thead>

<th></th>

<th></th>

<th></th>

<th></th>

<th></th>

<th>Email</th>

<th></th>

<th></th>

</thead>

<tbody>

<?foreach ($users as $user):?>

<tr>

<td id="tb-id"><?echo $user['id']?></td>

<td id="tb-lastname"><?echo $user['lastname']?></td>

<td id="tb-name"><?echo $user['name']?></td>

<td id="tb-patronymic"><?echo $user['patronymic']?></td>

<td id="tb-phone"><?echo $user['phone']?></td>

<td id="tb-email"><?echo $user['email']?></td>

<td id="tb-role-id"><?echo $user['role_comments']?></td>

<td id="tb-user-subdivisions">

<?if(!empty($user['subdivisions'])){

$user_subdivisions = array();

$user_subdivisions_id = array();

foreach ($user['subdivisions'] as $value) {

$user_subdivisions[] = $value['name'];

$user_subdivisions_id[] = $value['id'];

}

echo implode(',', $user_subdivisions);

echo "<span class='hidden-id'>".implode(',', $user_subdivisions_id)."</span>";

}?>

</td>

</tr>

<?endforeach?>

</tbody>

</table>

</div>

<div style="display: none;">

<div class="box-modal" id="new-entity">

<div class="box-modal_close arcticmodal-close"></div>

<div class="wrapper-create-user">

<p>Email:</p>

<input id="email" type="text" name="email" />

<p>:</p>

<input id="password" type="password" name="password" />

<p>:</p>

<input id="lastname" type="text" name="lastname" />

<p>:</p>

<input id="name" type="text" name="name" />

<p>:</p>

<input id="patronymic" type="text" name="patronymic" />

<p>:</p>

<input id="phone" type="text" name="phone" />

<p>:</p>

<select id="role-id" name="role-id">

<?foreach ($roles as $role):?>

<option value="<?echo $role['id']?>"><?echo $role['comments']?></option>

<?endforeach?>

</select>

<p>:</p>

<select id="user_subdivisions" data-placeholder="..." class="chosen-select" multiple name="user_subdivisions">

<?foreach ($subdivisions as $subdivision):?>

<option value="<?echo $subdivision['id']?>"><?echo $subdivision['name']?></option>

<?endforeach?>

</select>

 

<button type="button" class="btn btn-success create-object"></button>

</div>

</div>

</div>

 

<div style="display: none;">

<div class="box-modal" id="edit-entity">

<div class="box-modal_close arcticmodal-close"></div>

<div class="wrapper-create-user">

<p>:</p>

<input id="edit_lastname" type="text" name="lastname" />

<p>:</p>

<input id="edit_name" type="text" name="name" />

<p>:</p>

<input id="edit_patronymic" type="text" name="patronymic" />

<p>:</p>

<input id="edit_phone" type="text" name="phone" />

<p>Email:</p>

<input id="edit_email" type="text" name="email" />

<p>:</p>

<input id="edit_password" type="password" name="password" />

<p>:</p>

<select id="edit_role-id" name="role-id">

<?foreach ($roles as $role):?>

<option value="<?echo $role['id']?>" data-name="<?echo $role['comments']?>"><?echo $role['comments']?></option>

<?endforeach?>

</select>

<p>:</p>

<select id="edit_user_subdivisions" data-placeholder="..." class="chosen-select" multiple name="edit_user_subdivisions">

<?foreach ($subdivisions as $subdivision):?>

<option value="<?echo $subdivision['id']?>"><?echo $subdivision['name']?></option>

<?endforeach?>

</select>

<button type="button" class="btn btn-warning edit-object"></button>

</div>

</div>

</div>

<script>

$(document).ready(function(){

$('#issues-finished-at, #edit_issues-finished-at').datepicker({

format: 'yyyy-mm-dd',

});

 

$("#issues-responsibles, #edit_issues-responsibles, #user_subdivisions, #edit_user_subdivisions").chosen({width: "100%"});

$("#issues-performers, #edit_issues-performers").chosen({width: "100%"});

$('.crud-btn.btn-success').click(function(){

$('#new-entity').arcticmodal();

});

 

$('.create-object').click(function(){

var password = $('#password').val();

var lastname = $('#lastname').val();

var name = $('#name').val();

var patronymic = $('#patronymic').val();

var phone = $('#phone').val();

var email = $('#email').val();

var role_id = $("#role-id option:selected").val();

var user_subdivisions = $("#user_subdivisions").chosen().val();

 

$.ajax({

type: 'POST',

data: { password: password, lastname: lastname, name: name, patronymic: patronymic, phone: phone, email: email, role_id: role_id, user_subdivisions: user_subdivisions},

url: '<?=Uri::create("admin/users/create_user")?>',

dataType: "json",

success: function (data, textStatus) {

if(data == "OK") window.location.href = "<?=Uri::create("admin/users/list")?>";

$('.error-text').remove();

if(data == "1") $('#name').after("<p class='error-text'> !</p>");

}

});

});

 

//

$('.table-objects td').click(function(){

$('.table-objects tr').removeClass('select-tr');

$(this).parent().addClass('select-tr');

});

 

//

$('.crud-btn.btn-warning').click(function(){

if($('.table-objects tr').hasClass('select-tr')){

$('#edit_lastname').val($('.select-tr #tb-lastname').html());

$('#edit_name').val($('.select-tr #tb-name').html());

$('#edit_patronymic').val($('.select-tr #tb-patronymic').html());

$('#edit_phone').val($('.select-tr #tb-phone').html());

$('#edit_email').val($('.select-tr #tb-email').html());

$('#edit_role-id option[data-name="' + $('.select-tr #tb-role-id').text() + '"]').attr("selected", "selected");

 

var hidden_id = $('.select-tr #tb-user-subdivisions.hidden-id').text();

if(hidden_id!= ''){

var hidden_id = hidden_id.split(',');

for(var i=0; i < hidden_id.length; i++){

$('#edit_user_subdivisions option[value="' + hidden_id[i] + '"]').attr("selected", "selected");

}

$("#edit_user_subdivisions").trigger("chosen:updated");

}else{

$('#edit_user_subdivisions option').each(function(){

$(this).prop('selected', false);

});

$("#edit_user_subdivisions").trigger("chosen:updated");

}

$('#edit-entity').arcticmodal();

}

});

 

$('.edit-object').click(function(){

var lastname = $('#edit_lastname').val();

var name = $('#edit_name').val();

var patronymic = $('#edit_patronymic').val();

var phone = $('#edit_phone').val();

var email = $('#edit_email').val();

var password = $('#edit_password').val();

var role_id = $('#edit_role-id option:selected').val();

var id = $('.select-tr #tb-id').html();

var edit_user_subdivisions = $('#edit_user_subdivisions').chosen().val();

 

$.ajax({

type: 'POST',

data: {lastname: lastname, name: name, patronymic: patronymic, id: id, phone: phone, email: email, password: password, role_id:role_id, edit_user_subdivisions: edit_user_subdivisions},

url: '<?=Uri::create("admin/users/edit_user")?>',

dataType: "json",

success: function (data, textStatus) {

if(data == "OK") window.location.href = "<?=Uri::create("admin/users/list")?>";

$('.error-text').remove();

if(data == "1") $('#edit_name').after("<p class='error-text'> !</p>");

}

});

});

 

//

$('.crud-btn.btn-danger').click(function(){

if($('.table-objects tr').hasClass('select-tr')){

var answer = confirm(" ?");

if(answer){

var id = $('.select-tr #tb-id').html();

$.ajax({

type: 'POST',

data: {id: id},

url: '<?=Uri::create("admin/users/delete_user")?>',

dataType: "json",

success: function (data, textStatus) {

if(data == "OK") window.location.href = "<?=Uri::create("admin/users/list")?>";

}

});

}

}

});

 

})

</script>

 

Issues.php

<?

use Model\Reference\Subdivisions as Subdivisions;

use Model\Reference\Objects as Objects;

use Model\Tasks\Issues as Issues;

use Model\Users;

use Model\System;

 

class Controller_Admin_Issues extends Controller_Admin_Main {

public function before() {

parent::before();

Lang::load('issues', 'issues', Session::get('language', Config::get('language')), true, true);

$actions_data = array('section' => $this->section);

$this->template->topside = Presenter::forge('admin/topside');

$this->template->header = View::forge('admin/header', $this->data_header);

$this->template->topside->set('title', __('issues.title'), false);

$this->template->actions = View::forge('actions.php', $actions_data);

}

 

public function action_index() {

$this->template->title = __('issues.title');

$actions_data = array('section' => 'admin_issue');

if($this->current_user['role_id'] == 12) $actions_data['role'] = 'admin';

$role_acls = json_decode($this->current_user['role_acls'], true);

if(isset($role_acls['Controller_Admin_Issues']['in_arhive'])) $actions_data['in_arhive'] = 'true';

$this->template->actions = View::forge('actions.php', $actions_data);

 

//

if(!empty($_FILES)){

$uploads_dir = UPLOADDIR;

foreach ($_FILES["file"]["error"] as $key => $error) {

if ($error == 0) {

$tmp_name = $_FILES["file"]["tmp_name"][$key];

$name = $_FILES["file"]["name"][$key];

move_uploaded_file($tmp_name, "$uploads_dir/$name");

$path_parts = pathinfo("$uploads_dir/$name");

$new_name = md5(date('Y-m-d H:i:s').$_FILES["file"]["name"][$key]);

rename("$uploads_dir/$name", "$uploads_dir/".$new_name.".".$path_parts['extension']);

//print_r($path_parts);

$data['name'] = $name;

$data['hash'] = $new_name;

$data['mime'] = $_FILES["file"]["type"][$key];

$data['ext'] = $path_parts['extension'];

$data['issue_id'] = \Input::post('id');

 

Issues::uploadFile($data);

}

}

Response::redirect('admin/issues');

}

 

//

$user_subdivisions = Users::getUserSubdivisions($this->user['id']);

 

// id ,

$array = array();

$only_user_subdivisions = array();

$data['subdivisions'] = Subdivisions::getAll();

foreach ($data['subdivisions'] as $key => $value) {

$array[] = array('id'=>(int)$value['id'], 'pid'=>(int)$value['parent_id'], 'header'=>$value['name']);

}

//

$result = array(); //

$pid[$level] = $level = 0; // : 0, 0

// ...

while ($level >= 0)

{

//

if ($e = each($array))

{

//

if ($e[1]['pid'] === $pid[$level])

{

// ,

$e[1]['level'] = $level;

$result[] = $e[1];

// , .

unset($array[$e[0]]);

// , ? :

foreach ($t = $array as $val)

{

//

if ($val['pid'] === $e[1]['id'])

{

// ,

// ,

$pid[++$level] = $e[1]['id'];

// ,

reset($array);

break;

}

}

}

}

// -

else

{

$level--;

reset($array);

}

}

 

 

if(!empty($user_subdivisions)){

foreach ($user_subdivisions as $value) {

if($value['parent_id'] == 0){

$flag = true;

foreach ($result as $key_result => $value_result) {

if($value_result['id']!= $value['id'] and $flag) {

continue;

}else{

$flag = false;

}

 

if(isset($result[$key_result + 1]) and $result[$key_result + 1]['level']!= 0) {

$only_user_subdivisions[] = $value_result['id'];

}else{

$only_user_subdivisions[] = $value_result['id'];

break;

}

}

}else{

if(!in_array($value['id'], $only_user_subdivisions)) $only_user_subdivisions[] = $value['id'];

}

}

}

 

$data['issues'] = Issues::getAll($only_user_subdivisions);

$data['objects'] = Objects::getAll();

$data['users'] = Users::getAll();

//

$temp_array = array();

foreach ($data['users'] as $key => $value) {

$temp_array[$value['id']] = $value['lastname']." ".$value['name']." ".$value['patronymic'];

}

asort($temp_array);

$data['users'] = $temp_array;

$this->template->content = View::forge('admin/issues/list', $data);

 

}

 

public function action_show_arhive() {

$this->template->title = __('issues.title');

$actions_data = array('section' => '');

$this->template->actions = View::forge('actions.php', $actions_data);

 

$data['issues'] = Issues::getAllArhive();

$data['objects'] = Objects::getAll();

$data['subdivisions'] = Subdivisions::getAll();

$data['users'] = Users::getAll();

$this->template->content = View::forge('admin/issues/list_arhive', $data);

}

 

public function action_edit_page($id) {

$this->template->title = __('issues.title');

$actions_data = array('section' => 'admin_issue');

if($this->current_user['role_id'] == 12) $actions_data['role'] = 'admin';

 

$actions_data['btn_edit'] = 'false';

$actions_data['in_arhive'] = 'false';

$role_acls = json_decode($this->current_user['role_acls'], true);

if(isset($role_acls['Controller_Admin_Issues']['in_arhive'])) $actions_data['in_arhive'] = 'true';

 

// ,

if($this->current_user['role_id'] == 12 || isset($role_acls['Controller_Admin_Issues']['get_responsibles_issue'])){

$actions_data['btn_edit'] = 'true';

}else{

$data['issues'] = Issues::getByID($id);

if(!empty($data['issues']) and $data['issues'][0]['issues_author_id'] == $this->current_user['id']){

$actions_data['btn_edit'] = 'true';

}

}

 

$this->template->actions = View::forge('actions.php', $actions_data);

 

//

if(!empty($_FILES)){

$uploads_dir = UPLOADDIR;

foreach ($_FILES["file"]["error"] as $key => $error) {

if ($error == 0) {

$tmp_name = $_FILES["file"]["tmp_name"][$key];

$name = $_FILES["file"]["name"][$key];

move_uploaded_file($tmp_name, "$uploads_dir/$name");

$path_parts = pathinfo("$uploads_dir/$name");

$new_name = md5(date('Y-m-d H:i:s').$_FILES["file"]["name"][$key]);

rename("$uploads_dir/$name", "$uploads_dir/".$new_name.".".$path_parts['extension']);

//print_r($path_parts);

$data['name'] = $name;

$data['hash'] = $new_name;

$data['mime'] = $_FILES["file"]["type"][$key];

$data['ext'] = $path_parts['extension'];

$data['issue_id'] = \Input::post('id');

 

Issues::uploadFile($data);

}

}

Response::redirect('admin/issues/');

}

 

if(!empty($id)){

$data['issues'] = Issues::getByID($id);

$data['objects'] = Objects::getAll();

$data['subdivisions'] = Subdivisions::getAll();

$data['users'] = Users::getAll();

//

foreach ($data['users'] as $key => $value) {

$temp_array[$value['id']] = $value['lastname']." ".$value['name']." ".$value['patronymic'];

}

asort($temp_array);

$data['users'] = $temp_array;

 

// ,

$thumb_directory = UPLOADDIR_THUMB; //

$orig_directory = UPLOADDIR; //

 

$dir_handle = @opendir($orig_directory); //

if ($dir_handle > 1){ //,

$allowed_types = array('jpg','jpeg','gif','png'); //

$file_parts=array();

$ext = '';

$title = '';

$i = 0;

 

while ($file = @readdir($dir_handle))

{

/* : */

if($file == '.' || $file == '..') continue;

// -

if (file_exists(UPLOADDIR_THUMB. $file)) {

continue;

}

 

$file_parts = explode('.',$file); //

$ext = strtolower(array_pop($file_parts));

 

/* ( ) : */

$title = implode('.', $file_parts);

$title = htmlspecialchars($title);

 

/* : */

if(in_array($ext, $allowed_types))

{

/* : */

$nw = 150;

$nh = 100;

$source = $orig_directory. $file;

$stype = explode(".", $source);

$stype = $stype[count($stype)-1];

$dest = $thumb_directory. $file;

 

$size = getimagesize($source);

$w = $size[0];

$h = $size[1];

 

switch($stype) {

case 'gif':

$simg = imagecreatefromgif($source);

break;

case 'jpg':

$simg = imagecreatefromjpeg($source);

break;

case 'JPG':

$simg = imagecreatefromjpeg($source);

break;

case 'jpeg':

$simg = imagecreatefromjpeg($source);

break;

case 'png':

$simg = imagecreatefrompng($source);

break;

}

 

$dimg = imagecreatetruecolor($nw, $nh);

$wm = $w/$nw;

$hm = $h/$nh;

$h_height = $nh/2;

$w_height = $nw/2;

 

if($w > $h) {

$adjusted_width = $w / $hm;

$half_width = $adjusted_width / 2;

$int_width = $half_width - $w_height;

imagecopyresampled($dimg, $simg, -$int_width, 0, 0, 0, $adjusted_width, $nh, $w, $h);

} elseif(($w < $h) || ($w == $h)) {

$adjusted_height = $h / $wm;

$half_height = $adjusted_height / 2;

$int_height = $half_height - $h_height;

 

imagecopyresampled($dimg, $simg, 0, -$int_height, 0, 0, $nw, $adjusted_height, $w, $h);

} else {

imagecopyresampled($dimg, $simg, 0, 0, 0, 0, $nw, $nh, $w, $h);

}

imagejpeg($dimg, $dest, 100);

}

}

 

/* */

@closedir($dir_handle);

}

 

//

isset($role_acls['Controller_Admin_Issues']['get_responsibles_issue']) and $this->current_user['role_id']!= 12? $data['acls_responsibles'] = 'true': $data['acls_responsibles'] = 'false';

 

$this->template->content = View::forge('admin/issues/edit', $data);

}

}

 

public function action_my_issues() {

$this->template->title = __('issues.title');

$actions_data = array('section' => '');

$acls = json_decode($this->current_user['role_acls']);

//print_r($this->current_user['id']);

$data['issues_responsibles'] = array();

$data['issues_performers'] = array();

//

if(isset($acls->Controller_Admin_Issues->get_responsibles_issue)) {

$data['issues_responsibles'] = Issues::get_responsibles_issue($this->current_user['id']);

$actions_data = array('section' => 'responsible');

}

if(isset($acls->Controller_Admin_Issues->get_performers_issue)) {

$data['issues_performers'] = Issues::get_performers_issue($this->current_user['id']);

$actions_data = array('section' => 'performers');

}

$data['issues'] = array_merge($data['issues_responsibles'], $data['issues_performers']);

if($this->current_user['role_id'] == 12){

$data['issues'] = Issues::getAll();

$actions_data = array('section' => 'my_issues');

$actions_data['role'] = 'admin';

}

 

$data['objects'] = Objects::getAll();

$data['subdivisions'] = Subdivisions::getAll();

$data['users'] = Users::getAll();

 

$this->template->actions = View::forge('actions.php', $actions_data);

$this->template->content = View::forge('admin/issues/my_issues', $data);

 

}

 

//

public function action_create_issue() {

$this->template->title = __('issues.title');

$actions_data = array('section' => 'admin_issue');

if($this->current_user['role_id'] == 12) $actions_data['role'] = 'admin';

$role_acls = json_decode($this->current_user['role_acls'], true);

if(isset($role_acls['Controller_Admin_Issues']['in_arhive'])) $actions_data['in_arhive'] = 'true';

$this->template->actions = View::forge('actions.php', $actions_data);

$data['error'] = '';

$data['objects'] = Objects::getAll();

$data['subdivisions'] = Subdivisions::getAll();

$data['users'] = Users::getAll();

//

foreach ($data['users'] as $key => $value) {

$temp_array[$value['id']] = $value['lastname']." ".$value['name']." ".$value['patronymic'];

}

//asort($temp_array, SORT_LOCALE_STRING);

asort($temp_array);

$data['users'] = $temp_array;

$create = \Input::post('create');

 

if(!empty($create)){

$data['issues_name'] = \Input::post('issues_name');

$data['issues_details'] = \Input::post('issues_details');

$data['object_name'] = \Input::post('object_name');

$data['subdivision_name'] = \Input::post('subdivision_name');

$data['issues_finished_at'] = \Input::post('issues_finished_at');

$data['issues_responsibles'] = explode(',', \Input::post('issues_responsibles'));

$data['issues_performers'] = explode(',', \Input::post('issues_performer'));

$data['author_id'] = $this->current_user['id'];

$data['created_at'] = date('Y-m-d');

if(empty($data['issues_name'])) {

//return json_encode('1');

$data['error'] = ' ';

$this->template->content = View::forge('admin/issues/create', $data);

return;

}

if(empty($data['object_name'])) {

//return json_encode('2');

$data['error'] = ' ';

$this->template->content = View::forge('admin/issues/create', $data);

return;

}

if(empty($data['subdivision_name'])) {

//return json_encode('3');

$data['error'] = ' ';

$this->template->content = View::forge('admin/issues/create', $data);

return;

}

if(empty($data['issues_finished_at'])) {

// return json_encode('4');

$data['error'] = ' ';

$this->template->content = View::forge('admin/issues/create', $data);

return;

}

if(empty($data['issues_responsibles'])) {

//return json_encode('5');

$data['error'] = ' ';

$this->template->content = View::forge('admin/issues/create', $data);

return;

}

 

$res = Issues::ajax_create_issue($data);

 

if($res){

// Email

$emails = Users::getEmailByIDs($data['issues_responsibles']);

if(!empty($emails)){

foreach ($emails as $key => $value) {

if(empty($value['email'])) continue;

 

$to = $value['email'];

$subject = "=?utf-8?B?". base64_encode(" "). "?=";

$message = ' "'.$data['issues_name'].'" ';

$headers = "Content-type: text/html; charset=utf-8 \r\n";

$headers.= 'From: [email protected]'. "\r\n".

'X-Mailer: PHP/'. phpversion();

mail($to, $subject, $message, $headers);

}

}

 

// Email

if(!empty($data['issues_performers'])){

$emails = Users::getEmailByIDs($data['issues_performers']);

//print_r($emails);

if(!empty($emails)){

foreach ($emails as $key => $value) {

if(empty($value['email'])) continue;

 

$to = $value['email'];

$subject = "=?utf-8?B?". base64_encode(" "). "?=";

$message = ' "'.$data['issues_name'].'" ';

$headers = "Content-type: text/html; charset=utf-8 \r\n";

$headers.= 'From: [email protected]'. "\r\n".

'X-Mailer: PHP/'. phpversion();

mail($to, $subject, $message, $headers);

}

}

}

 

//

$data['user_id'] = $this->current_user['id'];

$data['event_type'] = '';

$data['source'] = ' action_create_issue, issues.php';

$data['details'] = ' ';

System::setlog($data);

//

if(!empty($_FILES)){

$uploads_dir = UPLOADDIR;

foreach ($_FILES["file"]["error"] as $key => $error) {

if ($error == 0) {

$tmp_name = $_FILES["file"]["tmp_name"][$key];

$name = $_FILES["file"]["name"][$key];

move_uploaded_file($tmp_name, "$uploads_dir/$name");

$path_parts = pathinfo("$uploads_dir/$name");

$new_name = md5(date('Y-m-d H:i:s').$_FILES["file"]["name"][$key]);

rename("$uploads_dir/$name", "$uploads_dir/".$new_name.".".$path_parts['extension']);

//print_r($path_parts);

$data['name'] = $name;

$data['hash'] = $new_name;

$data['mime'] = $_FILES["file"]["type"][$key];

$data['ext'] = $path_parts['extension'];

$data['issue_id'] = $res[0];

 

Issues::uploadFile($data);

}

}

 

// ,

$thumb_directory = UPLOADDIR_THUMB; //

$orig_directory = UPLOADDIR; //

 

$dir_handle = @opendir($orig_directory); //

if ($dir_handle > 1){ //,

$allowed_types = array('jpg','jpeg','gif','png'); //

$file_parts=array();

$ext = '';

$title = '';

$i = 0;

 

while ($file = @readdir($dir_handle))

{

/* : */

if($file == '.' || $file == '..') continue;

// -

if (file_exists(UPLOADDIR_THUMB. $file)) {

continue;

}

 

$file_parts = explode('.',$file); //

$ext = strtolower(array_pop($file_parts));

 

/* ( ) : */

$title = implode('.', $file_parts);

$title = htmlspecialchars($title);

 

/* : */

if(in_array($ext, $allowed_types))

{

/* : */

$nw = 150;

$nh = 100;

$source = $orig_directory. $file;

$stype = explode(".", $source);

$stype = $stype[count($stype)-1];

$dest = $thumb_directory. $file;

 

$size = getimagesize($source);

$w = $size[0];

$h = $size[1];

 

switch($stype) {

case 'gif':

$simg = imagecreatefromgif($source);

break;

case 'jpg':

$simg = imagecreatefromjpeg($source);

break;

case 'JPG':

$simg = imagecreatefromjpeg($source);

break;

case 'jpeg':

$simg = imagecreatefromjpeg($source);

break;

case 'png':

$simg = imagecreatefrompng($source);

break;

}

 

$dimg = imagecreatetruecolor($nw, $nh);

$wm = $w/$nw;

$hm = $h/$nh;

$h_height = $nh/2;

$w_height = $nw/2;

 

if($w > $h) {

$adjusted_width = $w / $hm;

$half_width = $adjusted_width / 2;

$int_width = $half_width - $w_height;

imagecopyresampled($dimg, $simg, -$int_width, 0, 0, 0, $adjusted_width, $nh, $w, $h);

} elseif(($w < $h) || ($w == $h)) {

$adjusted_height = $h / $wm;

$half_height = $adjusted_height / 2;

$int_height = $half_height - $h_height;

 

imagecopyresampled($dimg, $simg, 0, -$int_height, 0, 0, $nw, $adjusted_height, $w, $h);

} else {

imagecopyresampled($dimg, $simg, 0, 0, 0, 0, $nw, $nh, $w, $h);

}

imagejpeg($dimg, $dest, 100);

}

}

 

/* */

@closedir($dir_handle);

}

}

 

Response::redirect('admin/issues');

 

}else{

Response::redirect('admin/issues/create_issue');

}

}

$this->template->content = View::forge('admin/issues/create', $data);

}

 

//

public function action_edit_issue() {

$data['object_name'] = \Input::post('object_name');

$data['issues_name'] = \Input::post('issues_name');

$data['issues_details'] = \Input::post('issues_details');

$data['issues_finished_at'] = \Input::post('issues_finished_at');

$data['issues_performers'] = \Input::post('issues_performers');

$data['issues_responsibles'] = \Input::post('issues_responsibles');

$data['subdivision_name'] = \Input::post('subdivision_name');

$data['author_id'] = $this->current_user['id'];

$data['created_at'] = date('Y-m-d');

$data['is_finished'] = \Input::post('is_finished');

$data['id'] = \Input::post('id');

$data['is_responsible'] = \Input::post('is_responsible');

if(empty($data['is_responsible'])){

if(empty($data['issues_name'])) return json_encode('1');

if(empty($data['issues_responsibles'])) return json_encode('2');

Issues::ajax_edit_issue($data);

//

$data['user_id'] = $this->current_user['id'];

$data['event_type'] = '';

$data['source'] = ' action_edit_issue, issues.php';

$data['details'] = ' - '.$data['id'];

System::setlog($data);

return json_encode("OK");

}else{

Issues::ajax_edit_issue($data);

//

$data['user_id'] = $this->current_user['id'];

$data['event_type'] = '';

$data['source'] = ' action_edit_issue, issues.php';

$data['details'] = ' - '.$data['id'].' ';

System::setlog($data);

return json_encode("OK");

}

 

}

 

// ( " ")

public function action_get_responsibles_issue() {

$data['object_name'] = \Input::post('object_name');

$data['issues_name'] = \Input::post('issues_name');

$data['issues_details'] = \Input::post('issues_details');

$data['issues_finished_at'] = \Input::post('issues_finished_at');

$data['issues_performers'] = \Input::post('issues_performers');

$data['issues_responsibles'] = \Input::post('issues_responsibles');

$data['subdivision_name'] = \Input::post('subdivision_name');

$data['author_id'] = $this->current_user['id'];

$data['created_at'] = date('Y-m-d');

$data['is_finished'] = \Input::post('is_finished');

$data['id'] = \Input::post('id');

$data['is_responsible'] = \Input::post('is_responsible');

if(empty($data['is_responsible'])){

if(empty($data['issues_name'])) return json_encode('1');

if(empty($data['issues_responsibles'])) return json_encode('2');

Issues::ajax_edit_issue($data);

//

$data['user_id'] = $this->current_user['id'];

$data['event_type'] = '';

$data['source'] = ' action_edit_issue, issues.php';

$data['details'] = ' - '.$data['id'];

System::setlog($data);

return json_encode("OK");

}else{

//print_r($data); die();

Issues::ajax_edit_issue($data);

//

$data['user_id'] = $this->current_user['id'];

$data['event_type'] = '';

$data['source'] = ' action_edit_issue, issues.php';

$data['details'] = ' - '.$data['id'].' ';

System::setlog($data);

return json_encode("OK");

}

}

 

//

public function action_delete_issue() {

$data['id'] = \Input::post('id');

if(empty($data['id'])) return json_encode('1');

Issues::ajax_delete_issue($data);

//

$data['user_id'] = $this->current_user['id'];

$data['event_type'] = '';

$data['source'] = ' action_delete_issue, issues.php';

$data['details'] = ' - '.$data['id'];

System::setlog($data);

return json_encode("OK");

}

 

//

public function action_in_arhive() {

$data['id'] = \Input::post('id');

if(empty($data['id'])) return json_encode('1');

Issues::ajax_in_arhive($data);

//

$data['user_id'] = $this->current_user['id'];

$data['event_type'] = '';

$data['source'] = ' action_in_arhive, issues.php';

$data['details'] = ' - '.$data['id']. ' ';

System::setlog($data);

return json_encode("OK");

}

 

//

public function action_delete_file() {

$data['id'] = \Input::post('id');

if(empty($data['id'])) return json_encode('1');

Issues::ajax_delete_file($data);

//

$data['user_id'] = $this->current_user['id'];

$data['event_type'] = '';

$data['source'] = ' action_delete_file, issues.php';

$data['details'] = ' ';

System::setlog($data);

return json_encode("OK");

}

}

?>

 

Create.php

 

<div class="container-fluid subline">

</div>

 

<div class="container-fluid">

<div class="wrapper-page">

<div class="wrapper-create-issues">

<div class="error"><?echo $error?></div>

<form id="form-create-file" action="" method="POST" enctype="multipart/form-data">

<p> :</p>

<input id="issues-name" type="text" name="issues_name" />

<p> :</p>

<textarea id="issues-details" name="issues_details" /></textarea>

<p> :</p>

<select id="object_name" name="object_name">

<?foreach ($objects as $object):?>

<option value="<?echo $object['id']?>"><?echo $object['name']?></option>

<?endforeach?>

</select>

<p>:</p>

<select id="subdivision-name" name="subdivision_name">

<?foreach ($subdivisions as $subdivision):?>

<option value="<?echo $subdivision['id']?>"><?echo $subdivision['name']?></option>

<?endforeach?>

</select>

<p> :</p>

<input id="issues_finished_at" type="text" name="issues_finished_at" />

<p>:</p>

<select id="issues_responsibles" data-placeholder="..." class="chosen-select" multiple name="issues_responsibles">

<?foreach ($users as $key => $user):?>

<option value="<?echo $key?>"><?echo $user?></option>

<?endforeach?>

</select>

<p>:</p>

<select id="issues_performers" data-placeholder="..." class="chosen-select" multiple name="issues_performer">

<?foreach ($users as $key =>$user):?>

<option value="<?echo $key?>"><?echo $user?></option>

<?endforeach?>

</select>

<p>:</p>

<input class="multi" id="issues-files" type="file" name="file[]" multiple/>

 

<button name="create" class="btn btn-success create-object" value=""></button>

</form>

</div>

</div>

</div>

<script>

$(document).ready(function(){

$('#issues_finished_at, #edit_issues_finished_at').datepicker({

format: 'yyyy-mm-dd',

weekStart: 1,

autoclose:true,

});

$(".fancy-img").fancybox();

$("#issues_responsibles, #edit_issues_responsibles").chosen({width: "100%"});

$("#issues_performers, #edit_issues_performers").chosen({width: "100%"});

$('table tr').dblclick(function(){

var id = $(this).find('#tb-id').html();

//console.log(id);

window.location.href = "<?=Uri::create("admin/issues/edit_page/")?>" + id;

})

 

$('.crud-btn.btn-success').click(function(){

//$('#new-entity').arcticmodal();

window.location.href = "<?=Uri::create("admin/issues/create_issue")?>";

});

 

$('.create-object').click(function(){

var issues_responsibles = $("#issues_responsibles").chosen().val();

var issues_performer = $("#issues_performers").chosen().val();

$('#form-create-file').append('<input type="hidden" name="issues_responsibles" value="'+issues_responsibles+'"/>');

$('#form-create-file').append('<input type="hidden" name="issues_performer" value="'+issues_performer+'"/>');

$('#form-create-file').submit();

});

 

//

$('.table-objects td').click(function(){

$('.table-objects tr').removeClass('select-tr');

$(this).parent().addClass('select-tr');

});

 

$('.crud-btn.btn-warning').click(function(){

var id = $('.select-tr #tb-id').html();

if(id > 0){

window.location.href = "<?=Uri::create("admin/issues/edit_page/")?>" + id;

}

});

 

//

$('.remove-file-btn').click(function(){

var answer = confirm(" ?");

if(answer){

var id = $(this).attr('data-id');

$.ajax({

type: 'POST',

data: {id: id},

url: '<?=Uri::create("admin/issues/delete_file")?>',

dataType: "json",

success: function (data, textStatus) {

if(data == "OK") window.location.href = "<?=Uri::create("admin/issues")?>";

}

});

}

});

//

$('.crud-btn.btn-info').click(function(){

if($('.table-objects tr').hasClass('select-tr')){

var answer = confirm(" ?");

if(answer){

var id = $('.select-tr #tb-id').html();

$.ajax({

type: 'POST',

data: {id: id},

url: '<?=Uri::create("admin/issues/in_arhive")?>',

dataType: "json",

success: function (data, textStatus) {

if(data == "OK") window.location.href = "<?=Uri::create("admin/issues")?>";

}

});

}

}

});

 

//

$('.crud-btn.btn-danger').click(function(){

if($('.table-objects tr').hasClass('select-tr')){

var answer = confirm(" ?");

if(answer){

var id = $('.select-tr #tb-id').htm





:


: 2016-12-18; !; : 283 |


:

:

: , .
==> ...

2139 - | 1777 -


© 2015-2024 lektsii.org - -

: 1.374 .