query("SET NAMES 'utf8'"); $this->db = $pdo; } private $fixFields = array(); private function get_req_types($type){ $types = array(); $sql_types = "SELECT id FROM requisitions_type WHERE (id={$type} or heir={$type}) AND del = 0"; $q_types = $this->db->query($sql_types); while($r_types = $this->db->fetch_assoc($q_types)){ $types[] = (int)$r_types['id']; } return $types; } private function get_clients(){ $userId = $_SESSION['id']; $bd_usl_managers = ''; $arrIdUser = array(); $usersId = array(); $usersPlan = array(); $user = new User; $user -> get($userId); //if($_SESSION['users_admin']){ //Для ПИА показывать всех клиентов $userId = $user->agencyId; //} $arrIdUser[] = "who_work = $userId"; $wid[] = "doers like '%"".$userId."":1%'"; $usersId[] = $userId; $user -> get($userId); if($user->agency){ $rez3 = $this->db->query("SELECT id FROM users WHERE id_manager=$userId"); while ($mm = $this->db->fetch_row($rez3)) { $arrIdUser[] = "who_work = " . $mm[0]; $wid[] = "doers like '%"".$mm[0]."":1%'"; $usersId[] = $mm[0]; $rez04 = $this->db->query("SELECT id FROM users WHERE id_manager=$mm[0]"); while ($mm2 = $this->db->fetch_row($rez04)) { $arrIdUser[] = "who_work = " . $mm2[0]; $wid[] = "doers like '%"".$mm2[0]."":1%'"; $usersId[] = $mm2[0]; } } } else if($user->manager){ $rez04 = $this->db->query("SELECT id FROM users WHERE id_manager=$userId"); while ($mm2 = $this->db->fetch_row($rez04)) { $arrIdUser[] = "who_work = " . $mm2[0]; $wid[] = "doers like '%"".$mm2[0]."":1%'"; $usersId[] = $mm2[0]; } } $bd_usl_managers = " AND (".implode(" OR ",$arrIdUser).")"; if(!empty($wid)){ $bd_usl_managers = " AND ((".implode(" OR ",$arrIdUser).") or (".implode(" OR ",$wid)."))"; } $sql = "SELECT `id`, fio, email, phone, objects, deleted, confirm FROM clients WHERE 1 $bd_usl_managers order by deleted limit 30"; // echo $sql; $clients_all = array(); $q = $this->db->query($sql); while($r = $this->db->fetch_assoc($q)){ $res['id'] = $r['id']; $res['color'] = '#000'; if($r['deleted'] == 1){ $res['color'] = '#dd6360'; if($r['confirm'] == 10){ $res['color'] = '#43A047'; } } $res['name'] = $r['phone'].' '.$r['fio']; if(!empty($r['email'])){ $res['name'] = $r['phone'].' '.$r['fio'].' ('.$r['email'].')'; } if(isset($id) && $id>0){ $clients_all = $res; } else { $clients_all[] = $res; } } return $clients_all; } public function getFixFields(){ $types_price = $this->get_req_types(2); $fields = array(); $fields[] = [ 'id' => 'tags', 'title' => "Теги", 'is_filtrable' => 0, 'type' => 2, 'is_client' => 1, 'is_req' => 1, 'req_type' => 0, 'is_required' => 0, 'params' => [], 'is_podgroup' => 0, 'is_check_req' => 0, 'is_check_client' => 0, ]; $fields[] = [ 'id' => 'prep_price', 'title' => "Предварительная цена", 'is_filtrable' => 0, 'type' => 1, 'is_client' => 0, 'is_req' => 1, 'req_type' => json_encode($types_price), 'is_required' => 0, 'params' => [], 'is_podgroup' => 0, 'is_check_req' => 0, 'is_check_client' => 0, 'table' => 'object_prices', 'ident' => 'object_id', ]; $fields[] = [ 'id' => 'start_price', 'title' => "Начальная цена", 'is_filtrable' => 0, 'type' => 1, 'is_client' => 0, 'is_req' => 1, 'req_type' => json_encode($types_price), 'is_required' => 0, 'params' => [], 'is_podgroup' => 0, 'is_check_req' => 0, 'is_check_client' => 0, 'table' => 'object_prices', 'ident' => 'object_id', ]; $fields[] = [ 'id' => 'fact_price', 'title' => "Фактическая цена", 'is_filtrable' => 0, 'type' => 1, 'is_client' => 0, 'is_req' => 1, 'req_type' => json_encode($types_price), 'is_required' => 0, 'params' => [], 'is_podgroup' => 0, 'is_check_req' => 0, 'is_check_client' => 0, 'table' => 'object_prices', 'ident' => 'object_id', ]; $fields[] = [ 'id' => 'description', 'title' => "Описание", 'is_filtrable' => 0, 'type' => 5, 'is_client' => 1, 'is_req' => 1, 'req_type' => 0, 'is_required' => 0, 'params' => [], 'is_podgroup' => 0, 'is_check_req' => 0, 'is_check_client' => 0, ]; return $fields; } public function field_find($id){ $fieldFind = array(); $fields = $this->getFixFields(); foreach($fields as $field){ if($field['id'] == $id){ $fieldFind = $field; break; } } return $fieldFind; } public function getFixetForm(){ $types_form = $this->get_req_types(2); $forms = array(); $forms[] = [ 'id' => 'specifications_object', 'title' => 'Характеристики объекта', 'dop_selector' => '', 'req_type' => json_encode($types_form), 'is_check_req' => 0, 'is_check_client' => 0, 'is_client' => 0, 'is_req' => 1, ]; $forms[] = [ 'id' => 'contract_form', 'title' => 'Добавить договор', 'dop_selector' => '', 'req_type' => 0, 'is_check_req' => 0, 'is_check_client' => 0, 'is_client' => 1, 'is_req' => 1, ]; return $forms; } }