send_mail($id_empr); return true; } function print_relance($id_empr,$mail=true) { global $mailretard_priorite_email, $mailretard_priorite_email_2, $mailretard_priorite_email_3; global $msg, $pmb_gestion_financiere, $pmb_gestion_amende; global $mail_sended; $mail_sended=0; $not_mail=0; if (($pmb_gestion_financiere)&&($pmb_gestion_amende)) { $req="delete from cache_amendes where id_empr=".$id_empr; pmb_mysql_query($req); $amende=new amende($id_empr); $level=$amende->get_max_level(); $niveau_min=$level["level_min"]; $id_expl=$level["level_min_id_expl"]; $total_amende = $amende->get_total_amendes(); } //Si mail de rappel affecté au groupe, on envoi au responsable $requete="select id_groupe,resp_groupe from groupe,empr_groupe where id_groupe=groupe_id and empr_id=$id_empr and resp_groupe and mail_rappel limit 1"; $res=pmb_mysql_query($requete); if(pmb_mysql_num_rows($res) > 0) { $requete="select empr_mail from empr where id_empr='".pmb_mysql_result($res,0,1)."'"; $res=pmb_mysql_query($requete); if (@pmb_mysql_num_rows($res)) { list($empr_mail)=pmb_mysql_fetch_row($res); } } else { $requete="select empr_mail from empr where id_empr=$id_empr"; $resultat=pmb_mysql_query($requete); if (@pmb_mysql_num_rows($resultat)) { list($empr_mail)=pmb_mysql_fetch_row($resultat); } } if ($niveau_min) { //Si c'est un mail //JP 05/06/2017 : je passe par un flag car l'imbrication de conditions se complique... $flag_print=false; if (((($mailretard_priorite_email==1)||($mailretard_priorite_email==2))&&($empr_mail))&&( ($niveau_min<3)||($mailretard_priorite_email_3) )&&($mail)) { $flag_print=true; if (($niveau_min==2) && ($mailretard_priorite_email==1) && ($mailretard_priorite_email_2==1)) { //On force en lettre $flag_print=false; } } if ($flag_print) { if (send_mail($id_empr,$niveau_min)) { $requete="update pret set printed=1 where pret_idexpl=".$id_expl; pmb_mysql_query($requete); $mail_sended=1; } //3ème niveau de relance par mail et par lettre if (($niveau_min==3) && ($mailretard_priorite_email_3==2)) { $requete="update pret set printed=2 where pret_idexpl=".$id_expl; pmb_mysql_query($requete); $not_mail=1; } } else { $requete="update pret set printed=2 where pret_idexpl=".$id_expl; pmb_mysql_query($requete); $not_mail=1; } } $req="delete from cache_amendes where id_empr=".$id_empr; pmb_mysql_query($req); //On loggue les infos de la lettre $niveau_courant = $niveau_min; if($niveau_courant){ $niveau_suppose = $level["level_normal"]; $cpt_id=comptes::get_compte_id_from_empr($id_empr,2); $cpt=new comptes($cpt_id); $solde=$cpt->update_solde(); $frais_relance=$cpt->summarize_transactions("","",0,$realisee=-1); if ($frais_relance<0) $frais_relance=-$frais_relance; else $frais_relance=0; $req="insert into log_retard (niveau_reel,niveau_suppose,amende_totale,frais,idempr,log_printed,log_mail) values('".$niveau_courant."','".$niveau_suppose."','".$total_amende."','".$frais_relance."','".$id_empr."', '".$not_mail."', '".$mail_sended."')"; pmb_mysql_query($req); $id_log_ret = pmb_mysql_insert_id(); $reqexpl = "select pret_idexpl as expl from pret where pret_retour< CURDATE() and pret_idempr=$id_empr"; $resexple=pmb_mysql_query($reqexpl); while(($liste = pmb_mysql_fetch_object($resexple))){ $dates_resa_sql = " date_format(pret_date, '".$msg["format_date"]."') as aff_pret_date, date_format(pret_retour, '".$msg["format_date"]."') as aff_pret_retour " ; $requete = "SELECT notices_m.notice_id as m_id, notices_s.notice_id as s_id, pret_idempr, expl_id, expl_cb,expl_cote, pret_date, pret_retour, tdoc_libelle, section_libelle, location_libelle, trim(concat(ifnull(notices_m.tit1,''),ifnull(notices_s.tit1,''),' ',ifnull(bulletin_numero,''), if (mention_date!='', concat(' (',mention_date,')') ,''))) as tit, ".$dates_resa_sql.", " ; $requete.= " notices_m.tparent_id, notices_m.tnvol " ; $requete.= " FROM (((exemplaires LEFT JOIN notices AS notices_m ON expl_notice = notices_m.notice_id ) LEFT JOIN bulletins ON expl_bulletin = bulletins.bulletin_id) LEFT JOIN notices AS notices_s ON bulletin_notice = notices_s.notice_id), docs_type, docs_section, docs_location, pret "; $requete.= " WHERE expl_id='".$liste->expl."' and expl_typdoc = idtyp_doc and expl_section = idsection and expl_location = idlocation and pret_idexpl = expl_id "; $res_det_expl = pmb_mysql_query($requete) ; $expl = pmb_mysql_fetch_object($res_det_expl); if (($pmb_gestion_financiere)&&($pmb_gestion_amende)) { $amd = $amende->get_amende($liste->expl); } $req_ins="insert into log_expl_retard (titre,expl_id,expl_cb,date_pret,date_retour,amende,num_log_retard) values('".addslashes($expl->tit)."','".$expl->expl_id."','".$expl->expl_cb."','".$expl->pret_date."','".$expl->pret_retour."','".$amd["valeur"]."','".$id_log_ret."')"; pmb_mysql_query($req_ins); } } return $not_mail; } // Pour localiser les relances : $deflt2docs_location, $pmb_lecteurs_localises, $empr_location_id ; $loc_filter = ""; if ($pmb_lecteurs_localises) { $loc_filter = "and empr_location = '".$deflt2docs_location."' "; } //Traitement avant affichage if(!empty($relance_solo)) { readers_relances_controller::set_id_empr($relance_solo); } if(empty($empr) && !empty($readers_relances_ui_selected_objects)) { $empr = $readers_relances_ui_selected_objects; } if(!empty($empr)) { readers_relances_controller::set_empr($empr); } //switch $act if(!empty($act)) { readers_relances_controller::proceed(); unset($act); } echo "