id_transfert); } /** * Initialisation des filtres de recherche */ public function init_filters($filters=array()) { global $deflt_docs_location; /** * etat_transfert => (0 = non fini) * etat_demande => (0 = non validée, 1 = validée, 2 = envoyée, 3 = aller fini, 4 = refus) * type_transfert => (1 = aller-retour) */ $this->filters = array( 'site_origine' => $deflt_docs_location, 'site_destination' => 0, 'f_etat_date' => '', 'f_etat_dispo' => '', 'etat_transfert' => '', 'etat_demande' => '', 'type_transfert' => '', 'ids' => '', 'cb' => '' ); parent::init_filters($filters); } /** * Initialisation des colonnes disponibles */ protected function init_available_columns() { $this->available_columns = array('main_fields' => array( 'record' => '233', 'cb' => '232', 'empr' => 'transferts_circ_empr', 'source' => 'transferts_circ_source', 'destination' => 'transferts_circ_destination', 'expl_owner' => '651', 'formatted_date_creation' => 'transferts_circ_date_creation', 'formatted_date_envoyee' => 'transferts_circ_date_envoi', 'formatted_date_refus' => 'transferts_circ_date_refus', 'formatted_date_reception' => 'transferts_circ_date_reception', 'formatted_date_retour' => 'transferts_circ_date_retour', 'motif' => 'transferts_circ_motif', 'transfert_ask_user_num' => 'transferts_edition_ask_user', 'transfert_send_user_num' => 'transferts_edition_send_user', ) ); $this->available_columns['custom_fields'] = array(); $this->add_custom_fields_available_columns('notices', 'num_notice'); $this->add_custom_fields_available_columns('expl', 'num_exemplaire'); } /** * Initialisation de la pagination par défaut */ protected function init_default_pager() { global $transferts_tableau_nb_lignes; parent::init_default_pager(); $this->pager['nb_per_page'] = $transferts_tableau_nb_lignes; } /** * Initialisation du tri par défaut appliqué */ protected function init_default_applied_sort() { $this->add_applied_sort('formatted_date_creation', 'desc'); } /** * Initialisation des settings par défaut */ protected function init_default_settings() { parent::init_default_settings(); $this->set_setting_display('search_form', 'unfolded_filters', true); $this->set_setting_column('default', 'align', 'left'); } /** * Tri SQL */ protected function _get_query_order() { if($this->applied_sort[0]['by']) { $order = ''; $sort_by = $this->applied_sort[0]['by']; switch($sort_by) { case 'id': $order .= 'id_transfert'; break; case 'record' : break; case 'section': $order .= 'section_libelle'; break; case 'cote': $order .= 'expl_cote'; break; case 'cb': $order .= 'expl_cb'; break; case 'statut': $order .= 'statut_libelle'; break; case 'empr': $order .= "concat(empr_nom,' ',empr_prenom)"; break; case 'expl_owner': $order .= "lender_libelle"; break; case 'source': $order .= "loco.location_libelle"; break; case 'destination': $order .= "locd.location_libelle"; break; case 'formatted_date_creation': $order .= "transferts.date_creation"; break; case 'formatted_date_reception': $order .= "date_reception"; break; case 'formatted_date_envoyee': $order .= "date_envoyee"; break; case 'formatted_date_refus': $order .= "date_visualisee"; break; case 'motif_refus': $order .= "motif_refus"; break; case 'transfert_ask_formatted_date': $order .= "transfert_ask_date"; break; case 'formatted_bt_date_retour': case 'date_retour': $order .= "date_retour"; break; default : $order .= parent::_get_query_order(); break; } if($order) { return $this->_get_query_order_sql_build($order); } else { return ""; } } } /** * Filtres provenant du formulaire */ public function set_filters_from_form() { $site_origine = $this->objects_type.'_site_origine'; global ${$site_origine}; if(isset(${$site_origine}) && ${$site_origine} != '') { $this->filters['site_origine'] = ${$site_origine}*1; } $site_destination = $this->objects_type.'_site_destination'; global ${$site_destination}; if(isset(${$site_destination}) && ${$site_destination} != '') { $this->filters['site_destination'] = ${$site_destination}*1; } $this->set_filter_from_form('f_etat_date', 'integer'); $this->set_filter_from_form('f_etat_dispo', 'integer'); $numeros = ''; foreach ($_REQUEST as $k => $v) { //si c'est une case a cocher d'une liste if ((substr($k,0,4)=="sel_") && ($v=="1")) { //le no de transfert $numeros .= substr($k,4,strlen($k)) . ","; } } $this->filters['ids'] = ''; if($numeros) { //on enleve la derniere virgule $numeros = substr($numeros, 0, strlen($numeros)-1); $this->filters['ids'] = $numeros; } $this->set_filter_from_form('cb'); parent::set_filters_from_form(); } protected function get_search_options_locations($loc_select,$tous = true) { global $msg; $options = ''; $query = "SELECT idlocation, location_libelle FROM docs_location ORDER BY location_libelle "; $result = pmb_mysql_query($query); if ($tous) { $options .= ""; } while ($row = pmb_mysql_fetch_object($result)) { $options .= ""; } return $options; } protected function get_search_filter_site_origine() { $selector = ""; return $selector; } protected function get_search_filter_site_destination() { $selector = ""; return $selector; } protected function get_search_filter_f_etat_date() { global $msg, $charset; $selector = ""; return $selector; } protected function get_search_filter_f_etat_dispo() { global $msg, $charset; $selector = ""; return $selector; } protected function get_search_filter_cb() { global $charset; return ""; } /** * Filtre SQL */ protected function _get_query_filters() { global $transferts_nb_jours_alerte; $filter_query = ''; $this->set_filters_from_form(); $filters = array(); if($this->filters['site_origine']) { $filters [] = 'num_location_source = "'.$this->filters['site_origine'].'"'; } if($this->filters['site_destination']) { $filters [] = 'num_location_dest = "'.$this->filters['site_destination'].'"'; } if($this->filters['f_etat_date']) { switch ($this->filters['f_etat_date']) { case "1": $filters [] = "(DATEDIFF(DATE_ADD(date_retour,INTERVAL -" . $transferts_nb_jours_alerte . " DAY),CURDATE())<=0 AND DATEDIFF(date_retour,CURDATE())>=0)"; break; case "2": $filters [] = "DATEDIFF(date_retour,CURDATE())<0"; break; } } if($this->filters['f_etat_dispo']) { switch ($this->filters['f_etat_dispo']) { case 1 : // pas en pret et non réservé $filters [] = "if(id_resa, resa_confirmee=0, 1) and if(pret_idexpl,0 ,1) "; break; case 2 : // en pret et réservé seulement $filters [] = "( if(id_resa, resa_confirmee=1, 0) OR if(pret_idexpl,1 ,0) ) "; break; } } if($this->filters['etat_transfert'] !== '') { $filters [] = 'etat_transfert = "'.$this->filters['etat_transfert'].'"'; } if(is_array($this->filters['etat_demande'])) { $filters [] = 'etat_demande IN ('.implode(',', $this->filters['etat_demande']).')'; } elseif($this->filters['etat_demande'] !== '') { $filters [] = 'etat_demande = "'.$this->filters['etat_demande'].'"'; } if($this->filters['type_transfert'] !== '') { $filters [] = 'type_transfert = "'.$this->filters['type_transfert'].'"'; } if($this->filters['ids']) { $filters [] = 'id_transfert IN ('.$this->filters['ids'].')'; } if($this->filters['cb']) { $filters [] = 'exemplaires.expl_cb = "'.$this->filters['cb'].'"'; } if(count($filters)) { $filter_query .= ' where '.implode(' and ', $filters); } return $filter_query; } /** * Fonction de callback * @param object $a * @param object $b */ protected function _compare_objects($a, $b) { if($this->applied_sort[0]['by']) { $sort_by = $this->applied_sort[0]['by']; switch($sort_by) { case 'record' : if($a->get_num_notice()) { $content_a = aff_titre($a->get_num_notice(), 0); } else { $content_a = aff_titre(0, $a->get_num_bulletin()); } if($b->get_num_notice()) { $content_b = aff_titre($b->get_num_notice(), 0); } else { $content_b = aff_titre(0, $b->get_num_bulletin()); } return strcmp(strip_tags($content_a), strip_tags($content_b)); break; case 'section': case 'cote': case 'cb': return strcmp($a->get_exemplaire()->{$sort_by}, $b->get_exemplaire()->{$sort_by}); break; case 'statut': $docs_statut_a = new docs_statut($a->get_exemplaire()->statut_id); $docs_statut_b = new docs_statut($b->get_exemplaire()->statut_id); return strcmp($docs_statut_a->libelle, $docs_statut_b->libelle); break; case 'empr': $content_a = ''; $id_resa = $a->get_transfert_demande()->get_resa_trans(); if($id_resa) { $query = "select id_empr, empr_cb from empr join resa on id_empr = resa_idempr where id_resa = ".$id_resa; $result = pmb_mysql_query($query); if(pmb_mysql_num_rows($result) == 1) { $row = pmb_mysql_fetch_object($result); $content_a .= emprunteur::get_name($row->id_empr); } } $content_b = ''; $id_resa = $b->get_transfert_demande()->get_resa_trans(); if($id_resa) { $query = "select id_empr, empr_cb from empr join resa on id_empr = resa_idempr where id_resa = ".$id_resa; $result = pmb_mysql_query($query); if(pmb_mysql_num_rows($result) == 1) { $row = pmb_mysql_fetch_object($result); $content_b .= emprunteur::get_name($row->id_empr); } } return strcmp($content_a, $content_b); break; case 'expl_owner': $lender_a = new lender($a->get_exemplaire()->owner_id); $lender_b = new lender($b->get_exemplaire()->owner_id); return strcmp($lender_a->lender_libelle, $lender_b->lender_libelle); break; case 'source': $docs_location_a = new docs_location($a->get_transfert_demande()->get_num_location_source()); $docs_location_b = new docs_location($b->get_transfert_demande()->get_num_location_source()); return strcmp($docs_location_a->libelle, $docs_location_b->libelle); break; case 'destination': $docs_location_a = new docs_location($a->get_transfert_demande()->get_num_location_dest()); $docs_location_b = new docs_location($b->get_transfert_demande()->get_num_location_dest()); return strcmp($docs_location_a->libelle, $docs_location_b->libelle); break; case 'formatted_date_creation': return strcmp($a->get_date_creation(), $b->get_date_creation()); break; case 'formatted_date_reception': return strcmp($a->get_transfert_demande()->get_date_reception(), $b->get_transfert_demande()->get_date_reception()); break; case 'formatted_date_envoyee': return strcmp($a->get_transfert_demande()->get_date_envoyee(), $b->get_transfert_demande()->get_date_envoyee()); break; case 'formatted_date_refus': return strcmp($a->get_transfert_demande()->get_date_visualisee(), $b->get_transfert_demande()->get_date_visualisee()); break; case 'motif_refus': return strcmp($a->get_transfert_demande()->get_motif_refus(), $b->get_transfert_demande()->get_motif_refus()); break; case 'transfert_ask_formatted_date': return strcmp($a->get_transfert_ask_date(), $b->get_transfert_ask_date()); break; case 'transfert_ask_user_num': case 'transfert_send_user_num': return strcmp(user::get_param(call_user_func_array(array($a, "get_".$sort_by), array()), 'username'), user::get_param(call_user_func_array(array($b, "get_".$sort_by), array()), 'username')); break; case 'transfert_bt_relancer': return ''; break; case 'formatted_bt_date_retour': return strcmp($a->get_date_retour(), $b->get_date_retour()); break; default : return parent::_compare_objects($a, $b); break; } } } /** * Construction dynamique de la fonction JS de tri */ protected function get_js_sort_script_sort() { $display = parent::get_js_sort_script_sort(); $display = str_replace('!!categ!!', 'transferts', $display); $display = str_replace('!!sub!!', '', $display); $display = str_replace('!!action!!', 'list', $display); return $display; } protected function get_cell_content($object, $property) { global $msg; global $base_path; $content = ''; $is_cp_property = false; if(isset($this->displayed_cp) && is_array($this->displayed_cp)) { $is_cp_property = array_search($property, $this->displayed_cp); } if($is_cp_property) { $this->cp->get_values($object->get_exemplaire()->expl_id); if(isset($this->cp->values[$is_cp_property])) { $values = $this->cp->values[$is_cp_property]; } else { $values = array(); } $aff_column=$this->cp->get_formatted_output($values, $is_cp_property); if (!$aff_column) $aff_column=" "; $content .= $aff_column; } else { switch($property) { case 'record': if($object->get_num_notice()) { $content .= aff_titre($object->get_num_notice(), 0); } else { $content .= aff_titre(0, $object->get_num_bulletin()); } break; case 'section': case 'cote': $content .= $object->get_exemplaire()->{$property}; break; case 'cb': $content .= aff_exemplaire($object->get_exemplaire()->{$property}); break; case 'statut': $docs_statut = new docs_statut($object->get_exemplaire()->statut_id); $content .= aff_statut_exemplaire($docs_statut->libelle.'###'.$object->get_exemplaire()->expl_id); break; case 'empr': //TODO $id_resa = $object->get_transfert_demande()->get_resa_trans(); if($id_resa) { $query = "select id_empr, empr_cb from empr join resa on id_empr = resa_idempr where id_resa = ".$id_resa; $result = pmb_mysql_query($query); if(pmb_mysql_num_rows($result) == 1) { $row = pmb_mysql_fetch_object($result); if (SESSrights & CIRCULATION_AUTH) { $content = ""; $content .= emprunteur::get_name($row->id_empr); $content .= ""; } else { $content .= emprunteur::get_name($row->id_empr); } } } break; case 'expl_owner': $lender = new lender($object->get_exemplaire()->owner_id); $content .= $lender->lender_libelle; break; case 'source': $docs_location = new docs_location($object->get_transfert_demande()->get_num_location_source()); $content .= $docs_location->libelle; break; case 'destination': $docs_location = new docs_location($object->get_transfert_demande()->get_num_location_dest()); $content .= $docs_location->libelle; break; case 'formatted_date_reception': $content .= $object->get_transfert_demande()->get_formatted_date_reception(); break; case 'formatted_date_envoyee': $content .= $object->get_transfert_demande()->get_formatted_date_envoyee(); break; case 'formatted_date_refus': $content .= $object->get_transfert_demande()->get_formatted_date_visualisee(); break; case 'motif_refus': $content .= $object->get_transfert_demande()->get_motif_refus(); break; case 'transfert_ask_user_num': case 'transfert_send_user_num': $content .= user::get_param(call_user_func_array(array($object, "get_".$property), array()), 'username'); break; case 'transfert_bt_relancer': $content .= ""; break; case 'formatted_bt_date_retour': $content .= "get_form_name()."&date_caller='+".$this->get_form_name().".date_retour_".$object->get_id().".value.replace(reg,'')+'¶m1=date_retour_".$object->get_id()."¶m2=bt_date_retour_".$object->get_id()."&auto_submit=NO&date_anterieure=YES&after=chgDate%28id_value,".$object->get_id()."%29', 'calendar')\" /> "; break; default : $content .= parent::get_cell_content($object, $property); break; } } return $content; } protected function get_edition_link() { global $msg; global $sub; $edition_link = ''; //le lien pour l'édition si on a le droit ... if (SESSrights & EDIT_AUTH) { $sub_url = $sub; if($sub == 'departs' || $sub == 'valid' || $sub == 'retour') { switch (static::class) { case 'list_transferts_envoi_ui': $sub_url = 'envoi'; break; case 'list_transferts_retours_ui': $sub_url = 'retours'; break; case 'list_transferts_validation_ui': $sub_url = 'validation'; break; } } $url_edition = "./edit.php?categ=transferts&sub=".$sub_url; //on applique la seletion du filtre if ($this->filters['site_origine']) { $url_edition .= "&site_origine=" .$this->filters['site_origine']; } if ($this->filters['site_destination']) { $url_edition .= "&site_destination=" .$this->filters['site_destination']; } $edition_link = "".$msg[1100].""; } return $edition_link; } /** * Affichage des éléments de recherche */ public function get_search_content() { global $list_transferts_ui_parcours_search_content_form_tpl; $content_form = $list_transferts_ui_parcours_search_content_form_tpl; $content_form = str_replace('!!nb_res!!', $this->pager['nb_per_page'], $content_form); $content_form = str_replace('!!filters!!', $this->get_search_filters(), $content_form); $content_form = str_replace('!!json_filters!!', json_encode($this->filters), $content_form); $content_form = str_replace('!!page!!', $this->pager['page'], $content_form); $content_form = str_replace('!!nb_per_page!!', $this->pager['nb_per_page'], $content_form); $content_form = str_replace('!!pager!!', json_encode($this->pager), $content_form); $content_form = str_replace('!!objects_type!!', $this->objects_type, $content_form); $content_form = str_replace('!!edition_link!!', $this->get_edition_link(), $content_form); return $content_form; } protected function add_column_sel_button() { $this->columns[] = array( 'property' => '', 'label' => "
", 'html' => "", 'exportable' => false ); } public function get_display_list() { global $current_module; global $list_transferts_ui_script_case_a_cocher; $display = ''; if($current_module == 'circ') { $display .= "