id_empr); $emprunteur->set_pret_idexpl($row->expl_id); return $emprunteur; } protected function add_object($row) { global $all_level; if(is_array($all_level) && count($all_level)){ if (empty($all_level[$row->id_empr])) { $this->pager['nb_results']--; return; } } if ($all_level[$row->id_empr]) { $this->levels[$row->id_empr] = $all_level[$row->id_empr]; } else { $amende=$this->get_amende($row->id_empr); $this->levels[$row->id_empr] = $amende->get_max_level(); } if (($this->levels[$row->id_empr]["level_normal"])||($this->levels[$row->id_empr]["level_min"])) { $this->objects[] = $this->get_object_instance($row); } else { $this->pager['nb_results']--; } } /** * Initialisation de la pagination par défaut */ protected function init_default_pager() { parent::init_default_pager(); $this->pager['nb_per_page'] = pmb_mysql_result(pmb_mysql_query("SELECT count(*) FROM empr"), 0, 0); //Illimité $this->set_pager_in_session(); } /** * Initialisation des filtres disponibles */ protected function init_available_filters() { parent::init_available_filters(); $this->add_custom_fields_available_filters('pret', 'pret_idexpl'); } /** * Initialisation des colonnes disponibles */ protected function init_available_columns() { parent::init_available_columns(); $this->add_custom_fields_available_columns('pret', 'pret_idexpl'); //Ajout de colonnes HORS XML $this->available_columns['main_fields']['number_late'] = 'relance_nb_retard'; $this->available_columns['main_fields']['last_level'] = 'relance_dernier_niveau'; $this->available_columns['main_fields']['last_date'] = 'relance_date_derniere'; $this->available_columns['main_fields']['printed'] = 'relance_imprime'; $this->available_columns['main_fields']['supposed_level'] = 'relance_niveau_suppose'; } protected function init_no_sortable_columns() { parent::init_no_sortable_columns(); $this->no_sortable_columns[] = 'next_levels'; $this->no_sortable_columns[] = 'list_actions'; } protected function add_column_next_levels() { global $msg; $this->columns[] = array( 'property' => 'next_levels', 'label' => $msg['relance_action_prochaine'], 'html' => "", 'exportable' => false ); } protected function add_column_list_actions() { $this->columns[] = array( 'property' => 'list_actions', 'label' => "", 'html' => "", 'exportable' => false ); } /** * 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 'number_late': $query = "select count(pret_idexpl) as empr_nb from empr,pret where id_empr = ".$a->id." and pret_retourid." and pret_retourintcmp($number_late_a, $number_late_b); break; case 'last_level': return $this->intcmp($this->levels[$a->id]["level_min"], $this->levels[$b->id]["level_min"]); break; case 'last_date': return strcmp($this->levels[$a->id]["level_min_date_relance"], $this->levels[$b->id]["level_min_date_relance"]); break; case 'printed': return $this->intcmp($this->levels[$a->id]["printed"], $this->levels[$b->id]["printed"]); break; case 'supposed_level': return $this->intcmp($this->levels[$a->id]["level_normal"], $this->levels[$b->id]["level_normal"]); break; default : return parent::_compare_objects($a, $b); break; } } } protected function get_cell_content($object, $property) { global $msg; global $mailretard_priorite_email; global $mailretard_priorite_email_2; global $mailretard_priorite_email_3; $content = ''; switch($property) { case 'empr_name': $content .= "".$object->nom." ".$object->prenom.""; break; case 'number_late': $query = "select count(pret_idexpl) as empr_nb from empr,pret where id_empr = ".$object->id." and pret_retourlevels[$object->id]["level_min"]; break; case 'last_date': $date_relance=$this->levels[$object->id]["level_min_date_relance"]; $list_dates = array(); if(!isset($this->list_dates_sort)) $this->list_dates_sort = array(); if(!isset($this->list_dates_relance)) $this->list_dates_relance = array(); $list_dates[$date_relance]=format_date($date_relance); if ($this->levels[$object->id]["printed"]) { $this->list_dates_relance[$date_relance]=$list_dates[$date_relance]; $dr=explode("-",$date_relance); $this->list_dates_sort[$date_relance]=mktime(0,0,0,$dr[1],$dr[2],$dr[0]); } //Tri des dates if (count($this->list_dates_sort)) { arsort($this->list_dates_sort); } $content .= $list_dates[$date_relance]; break; case 'printed': $content .= ($this->levels[$object->id]["printed"] ? "X" : ""); break; case 'supposed_level': $content .= $this->levels[$object->id]["level_normal"]; break; case 'next_levels': $niveau_min = $this->levels[$object->id]["level_min"]; $niveau_normal = $this->levels[$object->id]["level_normal"]; $content .= relance::get_action($object->id,$niveau_min,$niveau_normal); break; case 'list_actions': // $script="envoi();"; // $content .= "id."'; this.form.act.value='solo'; this.form.relance_solo.value='".$object->id."'; $script\"/> "; $content .= "objects_type."_search_form'].action = document.forms['".$this->objects_type."_search_form'].action + '&act=solo&relance_solo=".$object->id."&action_".$object->id."='+document.getElementsByName('action_".$object->id."')[0].value+'#relance_empr_".$object->id."'; document.forms['".$this->objects_type."_search_form'].submit();\"/> "; //Si mail de rappel affecté au responsable du groupe $requete="select id_groupe,resp_groupe from groupe,empr_groupe where id_groupe=groupe_id and empr_id=".$object->id." and resp_groupe and mail_rappel limit 1"; $res=pmb_mysql_query($requete); if(pmb_mysql_num_rows($res) > 0) { $requete="select id_empr, empr_mail from empr where id_empr='".pmb_mysql_result($res, 0,1)."'"; $result=pmb_mysql_query($requete); $has_mail = (pmb_mysql_result($result, 0,1) ? 1 : 0); } else { $has_mail = ($object->mail ? 1 : 0); } $niveau_min = $this->levels[$object->id]["level_min"]; if ($niveau_min) { // $content .= "id."&niveau=".$niveau_min."','lettre'); this.form.act.value='solo_print'; this.form.relance_solo.value='".$object->id."'; $script\"/>"; $content .= "id."&niveau=".$niveau_min."','lettre'); document.forms['".$this->objects_type."_search_form'].action = document.forms['".$this->objects_type."_search_form'].action + '&act=solo_print&relance_solo=".$object->id."#relance_empr_".$object->id."'; document.forms['".$this->objects_type."_search_form'].submit();\"/>"; $flag_mail=false; if (((($mailretard_priorite_email==1)||($mailretard_priorite_email==2))&&($has_mail))&&(($niveau_min<3)||(($mailretard_priorite_email_3==1 || $mailretard_priorite_email_3==2) && $niveau_min>=3))) { $flag_mail=true; if (($niveau_min==2) && ($mailretard_priorite_email==1) && ($mailretard_priorite_email_2==1)) { //On force en lettre $flag_mail=false; } } if ($flag_mail) { // $content .= "id."#relance_empr_".$object->id."'; this.form.act.value='solo_mail'; this.form.relance_solo.value='".$object->id."'; $script\"/>"; $content .= "objects_type."_search_form'].action = document.forms['".$this->objects_type."_search_form'].action + '&act=solo_mail&relance_solo=".$object->id."#relance_empr_".$object->id."'; document.forms['".$this->objects_type."_search_form'].submit();\"/>"; } } break; default: $content .= parent::get_cell_content($object, $property); break; } return $content; } protected function get_grouped_label($object, $property) { global $msg; $grouped_label = ''; switch($property) { case 'number_late': $query = "select count(pret_idexpl) as empr_nb from empr,pret where id_empr = ".$object->id." and pret_retourlevels[$object->id]["level_min"]; break; case 'last_date': $date_relance=$this->levels[$object->id]["level_min_date_relance"]; $list_dates = array(); if(!isset($this->list_dates_sort)) $this->list_dates_sort = array(); if(!isset($this->list_dates_relance)) $this->list_dates_relance = array(); $list_dates[$date_relance]=format_date($date_relance); if ($this->levels[$object->id]["printed"]) { $this->list_dates_relance[$date_relance]=$list_dates[$date_relance]; $dr=explode("-",$date_relance); $this->list_dates_sort[$date_relance]=mktime(0,0,0,$dr[1],$dr[2],$dr[0]); } //Tri des dates if (count($this->list_dates_sort)) { arsort($this->list_dates_sort); } $grouped_label = $list_dates[$date_relance]; break; case 'printed': $grouped_label = ($this->levels[$object->id]["printed"] ? $msg['40'] : $msg['39']); break; case 'supposed_level': $grouped_label = $this->levels[$object->id]["level_normal"]; break; case 'next_levels': $grouped_label = $this->levels[$object->id]["level_normal"]; break; default: $grouped_label = parent::get_grouped_label($object, $property); break; } return $grouped_label; } protected function get_display_html_content_selection() { return "
"; } protected function init_default_columns() { $this->add_column_selection(); if(!empty(static::$used_filter_list_mode)) { $displaycolumns=explode(",",static::$filter_list->displaycolumns); //parcours des champs foreach ($displaycolumns as $displaycolumn) { if(substr($displaycolumn,0,2) == "#e") { $parametres_perso = $this->get_custom_parameters_instance('empr'); $custom_name = $parametres_perso->get_field_name_from_id(substr($displaycolumn,2)); $label = $this->get_label_available_column($custom_name, 'custom_fields'); $this->add_column($custom_name, $label); } else { $this->add_column(static::$correspondence_columns_fields['main_fields'][$displaycolumn]); } } } else { $this->add_column('cb'); $this->add_column('empr_name'); $this->add_column('categ_libelle'); $this->add_column('codestat_libelle'); $this->add_column('groups'); } //Afficher les CP de prêt if(!empty($this->custom_fields_available_columns)) { foreach ($this->custom_fields_available_columns as $name=>$column) { if($column['type'] == 'pret') { $parametres_perso = $this->get_custom_parameters_instance('pret'); $custom_id = $parametres_perso->get_field_id_from_name($name); $this->add_column($name, $parametres_perso->t_fields[$custom_id]['TITRE']); } } } $this->add_column('number_late'); $this->add_column('last_level'); $this->add_column('last_date'); $this->add_column('printed'); $this->add_column('supposed_level'); $this->add_column_next_levels(); $this->add_column_list_actions(); } protected function init_columns($columns=array()) { if(count($this->selected_columns)) { parent::init_columns($columns); $this->add_column_next_levels(); $this->add_column_list_actions(); } else { $this->init_default_columns(); } } protected function init_default_settings() { parent::init_default_settings(); $this->set_setting_display('search_form', 'export_icons', false); $this->set_setting_column('empr_name', 'align', 'left'); $this->set_setting_column('categ_libelle', 'align', 'left'); $this->set_setting_column('codestat_libelle', 'align', 'left'); $this->set_setting_column('groups', 'align', 'left'); $this->set_setting_column('list_actions', 'align', 'left'); } protected function _get_query_order() { $this->applied_sort_type = 'SQL'; return " group by id_empr ".parent::_get_query_order(); } protected function get_display_query_human($humans) { global $msg; return "

".implode(' '.$msg['search_and'].' ', $humans)."

"; } protected function get_selection_mode() { return 'button'; } protected function get_link_action($action, $msg_confirm='') { global $msg; return array( 'href' => static::get_controller_url_base()."&act=".$action, 'confirm' => $msg_confirm ); } protected function get_selection_actions() { global $msg; if(!isset($this->selection_actions)) { $this->selection_actions = array(); $this->selection_actions[] = $this->get_selection_action('valid_all', $msg['relance_valid_all'], 'tick.gif', $this->get_link_action('valid')); $this->selection_actions[] = $this->get_selection_action('print_nonprinted', $msg['relance_print_nonprinted'], 'print.gif', $this->get_link_action('print')); // $this->selection_actions[] = $this->get_selection_action('export', $msg['relance_export'], 'tableur.gif', $this->get_link_action('export')); $this->selection_actions[] = $this->get_selection_action('export_csv', $msg['relance_export_csv'], 'tableur.gif', $this->get_link_action('export_csv')); } return $this->selection_actions; } protected function get_name_selected_objects() { return "empr"; } protected function add_event_on_selection_action($action=array()) { global $msg; $display = " on(dom.byId('".$this->objects_type."_selection_action_".$action['name']."_link'), 'click', function() { var selection = new Array(); query('.".$this->objects_type."_selection:checked').forEach(function(node) { selection.push(node.value); }); if(selection.length) { var confirm_msg = '".(isset($action['link']['confirm']) ? addslashes($action['link']['confirm']) : '')."'; if(!confirm_msg || confirm(confirm_msg)) { ".(isset($action['link']['href']) && $action['link']['href'] ? " var selected_objects_form = domConstruct.create('form', { action : '".$action['link']['href']."', name : '".$this->objects_type."_selected_objects_form', id : '".$this->objects_type."_selected_objects_form', method : 'POST' }); selection.forEach(function(selected_option) { var selected_objects_hidden = domConstruct.create('input', { type : 'hidden', name : '".$this->get_name_selected_objects()."[]', value : selected_option }); domConstruct.place(selected_objects_hidden, selected_objects_form); var next_actions_hidden = domConstruct.create('input', { type : 'hidden', name : 'action_'+selected_option, value : dom.byId('action_'+selected_option).value }); domConstruct.place(next_actions_hidden, selected_objects_form); }); domConstruct.place(selected_objects_form, dom.byId('list_ui_selection_actions')); dom.byId('".$this->objects_type."_selected_objects_form').submit(); " : "")." ".(isset($action['link']['openPopUp']) && $action['link']['openPopUp'] ? "openPopUp('".$action['link']['openPopUp']."&selected_objects='+selection.join(','), '".$action['link']['openPopUpTitle']."'); return false;" : "")." ".(isset($action['link']['onClick']) && $action['link']['onClick'] ? $action['link']['onClick']."(selection); return false;" : "")." } } else { alert('".addslashes($msg['list_ui_no_selected'])."'); } }); "; return $display; } protected function get_display_others_actions() { global $msg; $display = ''; if (isset($this->list_dates_relance) && count($this->list_dates_relance)) { $display .= "
  "; } return $display; } protected static function init_correspondence_filters_fields() { parent::init_correspondence_filters_fields(); static::$correspondence_filters_fields['main_fields']['2'] = 'last_level_validated'; static::$correspondence_filters_fields['main_fields']['3'] = 'supposed_level'; } protected static function init_correspondence_columns_fields() { parent::init_correspondence_columns_fields(); static::$correspondence_columns_fields['main_fields']['2'] = 'last_level'; static::$correspondence_columns_fields['main_fields']['3'] = 'supposed_level'; } public function get_amende($id_empr) { if(!isset($this->amendes[$id_empr])) { $this->amendes[$id_empr] = new amende($id_empr); } return $this->amendes[$id_empr]; } }