diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index 47cee9903ef..3a062788059 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -48,6 +48,8 @@ $langs->load('companies'); $langs->load('compta'); $langs->load('bills'); +$action=GETPOST('action','alpha'); +$massaction=GETPOST('massaction','alpha'); $orderyear=GETPOST("orderyear","int"); $ordermonth=GETPOST("ordermonth","int"); $orderday=GETPOST("orderday","int"); @@ -70,6 +72,7 @@ $search_sale=GETPOST('search_sale','int'); $search_total_ht=GETPOST('search_total_ht','alpha'); $optioncss = GETPOST('optioncss','alpha'); $billed = GETPOST('billed','int'); +$toselect = GETPOST('toselect', 'array'); // Security check $id = (GETPOST('orderid')?GETPOST('orderid','int'):GETPOST('id','int')); @@ -183,6 +186,7 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETP $deliveryyear=''; $viewstatut=''; $billed=''; + $toselect=''; $search_array_options=array(); } @@ -201,6 +205,148 @@ if (empty($reshook)) $error++; } + // TODO Use a common inc.php file + if (! $error && $massaction == 'delete' && $user->rights->commande->supprimer) + { + $db->begin(); + + $objecttmp=new Commande($db); + $nbok = 0; + foreach($toselect as $toselectid) + { + $result=$objecttmp->fetch($toselectid); + if ($result > 0) + { + $result = $objecttmp->delete($user); + if ($result <= 0) + { + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; + } + else $nbok++; + } + else + { + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; + } + } + + if (! $error) + { + if ($nbok > 1) setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs'); + else setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs'); + $db->commit(); + } + else + { + $db->rollback(); + } + //var_dump($listofobjectthirdparties);exit; + } + + if (! $error && $massaction == "builddoc" && $user->rights->commande->lire && ! GETPOST('button_search')) + { + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; + + $objecttmp=new Commande($db); + $listofobjectid=array(); + $listofobjectthirdparties=array(); + $listofobjectref=array(); + foreach($toselect as $toselectid) + { + $objecttmp=new Commande($db); // must create new instance because instance is saved into $listofobjectref array for future use + $result=$objecttmp->fetch($toselectid); + if ($result > 0) + { + $listoinvoicesid[$toselectid]=$toselectid; + $thirdpartyid=$objecttmp->fk_soc?$objecttmp->fk_soc:$objecttmp->socid; + $listofobjectthirdparties[$thirdpartyid]=$thirdpartyid; + $listofobjectref[$toselectid]=$objecttmp->ref; + } + } + + $arrayofinclusion=array(); + foreach($listofobjectref as $tmppdf) $arrayofinclusion[]=preg_quote($tmppdf.'.pdf','/'); + $listoffiles = dol_dir_list($conf->commande->dir_output,'all',1,implode('|',$arrayofinclusion),'\.meta$|\.png','date',SORT_DESC,0,true); + + // build list of files with full path + $files = array(); + foreach($listofobjectref as $basename) + { + foreach($listoffiles as $filefound) + { + if (strstr($filefound["name"],$basename)) + { + $files[] = $conf->commande->dir_output.'/'.$basename.'/'.$filefound["name"]; + break; + } + } + } + + // Define output language (Here it is not used because we do only merging existing PDF) + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->thirdparty->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + + // Create empty PDF + $pdf=pdf_getInstance(); + if (class_exists('TCPDF')) + { + $pdf->setPrintHeader(false); + $pdf->setPrintFooter(false); + } + $pdf->SetFont(pdf_getPDFFont($outputlangs)); + + if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); + + // Add all others + foreach($files as $file) + { + // Charge un document PDF depuis un fichier. + $pagecount = $pdf->setSourceFile($file); + for ($i = 1; $i <= $pagecount; $i++) + { + $tplidx = $pdf->importPage($i); + $s = $pdf->getTemplatesize($tplidx); + $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L'); + $pdf->useTemplate($tplidx); + } + } + + // Create output dir if not exists + dol_mkdir($diroutputmassaction); + + // Save merged file + $filename=strtolower(dol_sanitizeFileName($langs->transnoentities("Orders"))); + if ($year) $filename.='_'.$year; + if ($month) $filename.='_'.$month; + if ($pagecount) + { + $now=dol_now(); + $file=$diroutputmassaction.'/'.$filename.'_'.dol_print_date($now,'dayhourlog').'.pdf'; + $pdf->Output($file,'F'); + if (! empty($conf->global->MAIN_UMASK)) + @chmod($file, octdec($conf->global->MAIN_UMASK)); + + $langs->load("exports"); + setEventMessages($langs->trans('FileSuccessfullyBuilt',$filename.'_'.dol_print_date($now,'dayhourlog')), null, 'mesgs'); + } + else + { + setEventMessages($langs->trans('NoPDFAvailableForDocGenAmongChecked'), null, 'errors'); + } + } } @@ -380,6 +526,8 @@ if ($resql) $num = $db->num_rows($resql); + $arrayofselected=is_array($toselect)?$toselect:array(); + $param=''; if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; @@ -408,8 +556,14 @@ if ($resql) if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val); } - //$massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge"))); - + $arrayofmassactions = array( + //'presend'=>$langs->trans("SendByMail"), + //'builddoc'=>$langs->trans("PDFMerge"), + ); + if ($user->rights->commande->supprimer) $arrayofmassactions['delete']=$langs->trans("Delete"); + if ($massaction == 'presend') $arrayofmassactions=array(); + $massactionbutton=$form->selectMassAction('', $arrayofmassactions); + // Lignes des champs de filtre print '
'; if ($optioncss != '') print ''; @@ -420,7 +574,7 @@ if ($resql) print ''; print ''; - print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_commercial.png', 0, '', '', $limit); + print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_commercial.png', 0, '', '', $limit); if ($sall) { @@ -657,7 +811,7 @@ if ($resql) } // Action column print ''; - $searchpitco=$form->showFilterAndCheckAddButtons(0); + $searchpitco=$form->showFilterAndCheckAddButtons($massactionbutton?1:0, 'checkforselect', 1); print $searchpitco; print ''; @@ -1001,7 +1155,14 @@ if ($resql) } // Action column - print ''; + print ''; + if ($massactionbutton) + { + $selected=0; + if (in_array($obj->rowid, $arrayofselected)) $selected=1; + print ''; + } + print ''; if (! $i) $totalarray['nbfield']++; print ''; diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 0e9c6874103..99103ee419a 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -205,12 +205,12 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter") || GETPOS $day=''; $year=''; $month=''; - $toselect=''; $option=''; $filter=''; $day_lim=''; $year_lim=''; $month_lim=''; + $toselect=''; $search_array_options=array(); } @@ -229,6 +229,7 @@ if (empty($reshook)) $error++; } + // TODO Use a common inc.php file if (! $error && $massaction == 'confirm_presend') { $resaction = ''; @@ -522,17 +523,17 @@ if (empty($reshook)) $arrayofinclusion=array(); foreach($listofobjectref as $tmppdf) $arrayofinclusion[]=preg_quote($tmppdf.'.pdf','/'); - $factures = dol_dir_list($conf->facture->dir_output,'all',1,implode('|',$arrayofinclusion),'\.meta$|\.png','date',SORT_DESC,0,true); + $listoffiles = dol_dir_list($conf->facture->dir_output,'all',1,implode('|',$arrayofinclusion),'\.meta$|\.png','date',SORT_DESC,0,true); - // liste les fichiers + // build list of files with full path $files = array(); foreach($listofobjectref as $basename) { - foreach($factures as $facture) + foreach($listoffiles as $filefound) { - if (strstr($facture["name"],$basename)) + if (strstr($filefound["name"],$basename)) { - $files[] = $conf->facture->dir_output.'/'.$basename.'/'.$facture["name"]; + $files[] = $conf->facture->dir_output.'/'.$basename.'/'.$filefound["name"]; break; } } @@ -831,7 +832,12 @@ if ($resql) if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val); } - $massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge"))); + $arrayofmassactions=array( + 'presend'=>$langs->trans("SendByMail"), + 'builddoc'=>$langs->trans("PDFMerge") + ); + if ($massaction == 'presend') $arrayofmassactions=array(); + $massactionbutton=$form->selectMassAction('', $arrayofmassactions); $i = 0; print ''."\n"; @@ -843,7 +849,7 @@ if ($resql) print ''; print ''; - print_barre_liste($langs->trans('BillsCustomers').' '.($socid?' '.$soc->name:''),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,$massactionbutton,$num,$nbtotalofrecords,'title_accountancy.png',0,'','',$limit); + print_barre_liste($langs->trans('BillsCustomers').' '.($socid?' '.$soc->name:''), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_accountancy.png', 0, '', '', $limit); if ($massaction == 'presend') { @@ -1183,7 +1189,7 @@ if ($resql) } // Action column print ''; - $searchpitco=$form->showFilterAndCheckAddButtons(1, 'checkforselect', 1); + $searchpitco=$form->showFilterAndCheckAddButtons($massactionbutton?1:0, 'checkforselect', 1); print $searchpitco; print ''; print "\n"; @@ -1423,9 +1429,12 @@ if ($resql) // Action column print ''; - $selected=0; - if (in_array($obj->facid, $arrayofselected)) $selected=1; - print ''; + if ($massactionbutton) + { + $selected=0; + if (in_array($obj->facid, $arrayofselected)) $selected=1; + print ''; + } print '' ; if (! $i) $totalarray['nbfield']++; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index ba60aa5f2c5..aed8a6b6ce0 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6014,7 +6014,7 @@ class Form /** * Return HTML to show the search and clear seach button * - * @param int $addcheckuncheckall Add the check all uncheck all button + * @param int $addcheckuncheckall Add the check all/uncheck all checkbox (use javascript) and code to manage this * @param string $cssclass CSS class * @param int $calljsfunction 0=default. 1=call function initCheckForSelect() after changing status of checkboxes * @return string @@ -6029,8 +6029,7 @@ class Form if ($addcheckuncheckall) { if (! empty($conf->use_javascript_ajax)) $out.=''; - } - $out.=''; + if ($calljsfunction) $out.='if (typeof initCheckForSelect == \'function\') { initCheckForSelect(); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }'; + $out.=' }); + }); + '; + } return $out; } } diff --git a/htdocs/core/db/mysql.class.php b/htdocs/core/db/mysql.class.php index a92bb09e0b3..85b3ea13b13 100644 --- a/htdocs/core/db/mysql.class.php +++ b/htdocs/core/db/mysql.class.php @@ -606,10 +606,13 @@ class DoliDBMysql extends DoliDB $sql="SHOW TABLES FROM ".$database." ".$like.";"; //print $sql; $result = $this->query($sql); - while($row = $this->fetch_row($result)) - { - $listtables[] = $row[0]; - } + if ($result) + { + while($row = $this->fetch_row($result)) + { + $listtables[] = $row[0]; + } + } return $listtables; } @@ -627,10 +630,13 @@ class DoliDBMysql extends DoliDB dol_syslog($sql,LOG_DEBUG); $result = $this->query($sql); - while($row = $this->fetch_row($result)) - { - $infotables[] = $row; - } + if ($result) + { + while($row = $this->fetch_row($result)) + { + $infotables[] = $row; + } + } return $infotables; } diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index b83d42810a8..087abf709d9 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -589,9 +589,12 @@ class DoliDBMysqli extends DoliDB $sql="SHOW TABLES FROM ".$database." ".$like.";"; //print $sql; $result = $this->query($sql); - while($row = $this->fetch_row($result)) + if ($result) { - $listtables[] = $row[0]; + while($row = $this->fetch_row($result)) + { + $listtables[] = $row[0]; + } } return $listtables; } @@ -610,9 +613,12 @@ class DoliDBMysqli extends DoliDB dol_syslog($sql,LOG_DEBUG); $result = $this->query($sql); - while($row = $this->fetch_row($result)) + if ($result) { - $infotables[] = $row; + while($row = $this->fetch_row($result)) + { + $infotables[] = $row; + } } return $infotables; } diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index 5a9a446596f..3290e259dca 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -861,10 +861,13 @@ class DoliDBPgsql extends DoliDB $like = ''; if ($table) $like = " AND table_name LIKE '".$table."'"; $result = pg_query($this->db, "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'".$like." ORDER BY table_name"); - while($row = $this->fetch_row($result)) - { - $listtables[] = $row[0]; - } + if ($result) + { + while($row = $this->fetch_row($result)) + { + $listtables[] = $row[0]; + } + } return $listtables; } diff --git a/htdocs/core/db/sqlite.class.php b/htdocs/core/db/sqlite.class.php index 647cd3a6798..ef638b0e9fe 100644 --- a/htdocs/core/db/sqlite.class.php +++ b/htdocs/core/db/sqlite.class.php @@ -747,9 +747,12 @@ class DoliDBSqlite extends DoliDB $sql="SHOW TABLES FROM ".$database." ".$like.";"; //print $sql; $result = $this->query($sql); - while($row = $this->fetch_row($result)) + if ($result) { - $listtables[] = $row[0]; + while($row = $this->fetch_row($result)) + { + $listtables[] = $row[0]; + } } return $listtables; } @@ -769,9 +772,12 @@ class DoliDBSqlite extends DoliDB dol_syslog($sql,LOG_DEBUG); $result = $this->query($sql); - while($row = $this->fetch_row($result)) + if ($result) { - $infotables[] = $row; + while($row = $this->fetch_row($result)) + { + $infotables[] = $row; + } } return $infotables; } diff --git a/htdocs/core/db/sqlite3.class.php b/htdocs/core/db/sqlite3.class.php index 2b9f2dedf8a..97ba05a32ba 100644 --- a/htdocs/core/db/sqlite3.class.php +++ b/htdocs/core/db/sqlite3.class.php @@ -831,9 +831,12 @@ class DoliDBSqlite3 extends DoliDB $sql="SHOW TABLES FROM ".$database." ".$like.";"; //print $sql; $result = $this->query($sql); - while($row = $this->fetch_row($result)) + if ($result) { - $listtables[] = $row[0]; + while($row = $this->fetch_row($result)) + { + $listtables[] = $row[0]; + } } return $listtables; } @@ -853,9 +856,12 @@ class DoliDBSqlite3 extends DoliDB dol_syslog($sql,LOG_DEBUG); $result = $this->query($sql); - while($row = $this->fetch_row($result)) + if ($result) { - $infotables[] = $row; + while($row = $this->fetch_row($result)) + { + $infotables[] = $row; + } } return $infotables; } diff --git a/htdocs/holiday/card.php b/htdocs/holiday/card.php index 81b9dbca14b..9b3494c762f 100644 --- a/htdocs/holiday/card.php +++ b/htdocs/holiday/card.php @@ -95,36 +95,41 @@ if ($action == 'create') // If no start date if (empty($date_debut)) { - header('Location: '.$_SERVER["PHP_SELF"].'?action=request&error=nodatedebut'); - exit; + setEventMessages($langs->trans("NoDateDebut"), null, 'errors'); + $error++; + $action='create'; } // If no end date if (empty($date_fin)) { - header('Location: '.$_SERVER["PHP_SELF"].'?action=request&error=nodatefin'); - exit; + setEventMessages($langs->trans("NoDateFin"), null, 'errors'); + $error++; + $action='create'; } // If start date after end date if ($date_debut > $date_fin) { - header('Location: '.$_SERVER["PHP_SELF"].'?action=request&error=datefin'); - exit; + setEventMessages($langs->trans("ErrorEndDateCP"), null, 'errors'); + $error++; + $action='create'; } // Check if there is already holiday for this period $verifCP = $cp->verifDateHolidayCP($userID, $date_debut, $date_fin, $halfday); if (! $verifCP) { - header('Location: '.$_SERVER["PHP_SELF"].'?action=request&error=alreadyCP'); - exit; + setEventMessages($langs->trans("alreadyCPexist"), null, 'errors'); + $error++; + $action='create'; } // If there is no Business Days within request $nbopenedday=num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday); if($nbopenedday < 0.5) { - header('Location: '.$_SERVER["PHP_SELF"].'?action=request&error=DureeHoliday'); - exit; + setEventMessages($langs->trans("ErrorDureeCP"), null, 'errors'); + $error++; + $action='create'; } // If no validator designated @@ -823,10 +828,10 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create print ''; // Si la demande ne vient pas de l'agenda if (! GETPOST('date_debut_')) { - $form->select_date(-1,'date_debut_'); + $form->select_date(-1, 'date_debut_', 0, 0, 0, '', 1, 1); } else { $tmpdate = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year')); - $form->select_date($tmpdate,'date_debut_'); + $form->select_date($tmpdate, 'date_debut_', 0, 0, 0, '', 1, 1); } print '     '; print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday')?GETPOST('starthalfday'):'morning')); @@ -839,10 +844,10 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create print ''; // Si la demande ne vient pas de l'agenda if (! GETPOST('date_fin_')) { - $form->select_date(-1,'date_fin_'); + $form->select_date(-1,'date_fin_', 0, 0, 0, '', 1, 1); } else { $tmpdate = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year')); - $form->select_date($tmpdate,'date_fin_'); + $form->select_date($tmpdate,'date_fin_', 0, 0, 0, '', 1, 1); } print '     '; print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday')?GETPOST('endhalfday'):'afternoon')); @@ -861,7 +866,7 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create print ''; print ''.$langs->trans("DescCP").''; print ''; - print ''; + print ''; print ''; print ''; diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php index a31bd28da49..b76c90cbf48 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -1364,330 +1364,10 @@ class Holiday extends CommonObject { if (empty($userCP)) $userCP=0; dol_syslog(get_class($this).'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.' userCP='.$userCP); -/* - // On vérifie les users Dolibarr sans CP - if ($userDolibarrWithoutCP > 0) - { - $this->db->begin(); - - //$this->updateConfCP('nbUser',$userDolibarrWithoutCP); - - $listUsersCP = $this->fetchUsers(true,false); - - // On séléctionne les utilisateurs qui ne sont pas déjà dans le module - $sql = "SELECT u.rowid, u.lastname, u.firstname"; - $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; - if ($listUsersCP != '') $sql.= " WHERE u.rowid NOT IN(".$listUsersCP.")"; - - $resql = $this->db->query($sql); - if ($resql) - { - $i = 0; - $num = $this->db->num_rows($resql); - - while($i < $num) - { - $obj = $this->db->fetch_object($resql); - $uid = $obj->rowid; - - // On ajoute l'utilisateur - //print "Add user rowid = ".$uid." into database holiday"; - - $result = $this->createCPusers(true,$uid); - - $i++; - } - - $this->db->commit(); - } else { - // Erreur SQL - $this->error="Error ".$this->db->lasterror(); - dol_syslog(get_class($this)."::verifNbUsers ".$this->error, LOG_ERR); - $this->db->rollback(); - return -1; - } - - } - else - { - $this->db->begin(); - - // Si il y a moins d'utilisateur Dolibarr que dans le module CP - - $this->updateConfCP('nbUser',$userDolibarrWithoutCP); - - $listUsersDolibarr = $this->fetchUsers(true,true); - - // On séléctionne les utilisateurs qui ne sont pas déjà dans le module - $sql = "SELECT u.fk_user"; - $sql.= " FROM ".MAIN_DB_PREFIX."holiday_users as u"; - $sql.= " WHERE u.fk_user NOT IN (".$listUsersDolibarr.")"; - - $resql = $this->db->query($sql); - - // Si pas d'erreur SQL - if ($resql) { - - $i = 0; - $num = $this->db->num_rows($resql); - - while($i < $num) { - - $obj = $this->db->fetch_object($resql); - - // On supprime l'utilisateur - $this->deleteCPuser($obj->fk_user); - - $i++; - } - - $this->db->commit(); - } else { - // Erreur SQL - $this->error="Error ".$this->db->lasterror(); - dol_syslog(get_class($this)."::verifNbUsers ".$this->error, LOG_ERR); - $this->db->rollback(); - return -1; - } - } -*/ return 1; } - /** - * Liste les évènements de congés payés enregistré - * - * @return int -1 si erreur, 1 si OK et 2 si pas de résultat - */ - function fetchEventsCP() - { - global $langs; - - $sql = "SELECT"; - $sql.= " cpe.rowid,"; - $sql.= " cpe.name,"; - $sql.= " cpe.value"; - - $sql.= " FROM ".MAIN_DB_PREFIX."holiday_events as cpe"; - - dol_syslog(get_class($this)."::fetchEventsCP", LOG_DEBUG); - $resql=$this->db->query($sql); - - // Si pas d'erreur SQL - if ($resql) { - - $i = 0; - $tab_result = $this->events; - $num = $this->db->num_rows($resql); - - // Si pas d'enregistrement - if(!$num) { - return 2; - } - - // On liste les résultats et on les ajoutent dans le tableau - while($i < $num) { - - $obj = $this->db->fetch_object($resql); - - $tab_result[$i]['rowid'] = $obj->rowid; - $tab_result[$i]['name'] = $obj->name; - $tab_result[$i]['value'] = $obj->value; - - $i++; - } - // Retourne 1 et ajoute le tableau à la variable - $this->events = $tab_result; - return 1; - } - else - { - // Erreur SQL - $this->error="Error ".$this->db->lasterror(); - return -1; - } - } - - /** - * Créer un évènement de congés payés - * - * @param User $user User - * @param int $notrigger No trigger - * @return int -1 si erreur, id si OK - */ - function createEventCP($user, $notrigger=0) - { - global $conf, $langs; - $error=0; - - // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_events ("; - - $sql.= "name,"; - $sql.= "value"; - - $sql.= ") VALUES ("; - - $sql.= " '".$this->db->escape($this->optName)."',"; - $sql.= " '".$this->optValue."'"; - $sql.= ")"; - - $this->db->begin(); - - dol_syslog(get_class($this)."::createEventCP", LOG_DEBUG); - $resql=$this->db->query($sql); - if (! $resql) { - $error++; $this->errors[]="Error ".$this->db->lasterror(); - } - - if (! $error) - { - $this->optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday_events"); - - } - - // Commit or rollback - if ($error) - { - foreach($this->errors as $errmsg) - { - dol_syslog(get_class($this)."::createEventCP ".$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); - } - $this->db->rollback(); - return -1*$error; - } - else - { - $this->db->commit(); - return $this->optRowid; - } - } - - /** - * Met à jour les évènements de congés payés - * - * @param int $rowid Row id - * @param string $name Name - * @param value $value Value - * @return int -1 si erreur, id si OK - */ - function updateEventCP($rowid, $name, $value) { - - $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_events SET"; - $sql.= " name = '".$this->db->escape($name)."', value = '".$value."'"; - $sql.= " WHERE rowid = '".$rowid."'"; - - $result = $this->db->query($sql); - - if($result) { - return true; - } - - return false; - } - - /** - * Select event - * - * @return string|false Select Html to select type of holiday - */ - function selectEventCP() - { - - $sql = "SELECT rowid, name, value"; - $sql.= " FROM ".MAIN_DB_PREFIX."holiday_events"; - - $result = $this->db->query($sql); - if ($result) - { - $num = $this->db->num_rows($result); - $i = 0; - - $out = ''; - - return $out; - } - else - { - return false; - } - } - - /** - * deleteEvent - * - * @param int $rowid Row id - * @return boolean Success or not - */ - function deleteEventCP($rowid) { - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."holiday_events"; - $sql.= " WHERE rowid = '".$rowid."'"; - - $result = $this->db->query($sql); - - if($result) { - return true; - } else { - return false; - } - } - - /** - * getValueEventCp - * - * @param int $rowid Row id - * @return string|false - */ - function getValueEventCp($rowid) { - - $sql = "SELECT value"; - $sql.= " FROM ".MAIN_DB_PREFIX."holiday_events"; - $sql.= " WHERE rowid = '".$rowid."'"; - - $result = $this->db->query($sql); - - if($result) { - $obj = $this->db->fetch_array($result); - return number_format($obj['value'],2); - } else { - return false; - } - } - - /** - * getNameEventCp - * - * @param int $rowid Row id - * @return unknown|boolean - */ - function getNameEventCp($rowid) { - - $sql = "SELECT name"; - $sql.= " FROM ".MAIN_DB_PREFIX."holiday_events"; - $sql.= " WHERE rowid = '".$rowid."'"; - - $result = $this->db->query($sql); - - if($result) { - $obj = $this->db->fetch_array($result); - return $obj['name']; - } else { - return false; - } - } - /** * addLogCP * diff --git a/htdocs/holiday/define_holiday.php b/htdocs/holiday/define_holiday.php index 7a94e686173..92a93a0d357 100644 --- a/htdocs/holiday/define_holiday.php +++ b/htdocs/holiday/define_holiday.php @@ -106,46 +106,6 @@ if ($action == 'update' && isset($_POST['update_cp'])) if (! $error) setEventMessages('UpdateConfCPOK', '', 'mesgs'); } -elseif($action == 'add_event') -{ - $error = 0; - - $typeleaves=$holiday->getTypes(1,1); - - if(!empty($_POST['list_event']) && $_POST['list_event'] > 0) { - $event = $_POST['list_event']; - } else { $error++; - } - - if(!empty($_POST['userCP']) && $_POST['userCP'] > 0) { - $userCP = $_POST['userCP']; - } else { $erro++; - } - - if ($error) - { - setEventMessages('ErrorAddEventToUserCP', '', 'errors'); - } - else - { - $nb_holiday = $holiday->getCPforUser($userCP); - $add_holiday = $holiday->getValueEventCp($event); - $new_holiday = $nb_holiday + $add_holiday; - - // add event to existing types of vacation - foreach ($typeleaves as $key => $leave) - { - $vacationTypeID = $leave['rowid']; - - // On ajoute la modification dans le LOG - $holiday->addLogCP($user->id,$userCP, $holiday->getNameEventCp($event),$new_holiday, $vacationTypeID); - - $holiday->updateSoldeCP($userCP,$new_holiday, $vacationTypeID); - } - - setEventMessages('AddEventToUserOkCP', '', 'mesgs'); - } -} /* @@ -186,24 +146,6 @@ if (is_numeric($listUsers) && $listUsers < 0) $var=true; $i = 0; -$cp_events = $holiday->fetchEventsCP(); -if ($cp_events == 1) -{ - print '
'."\n"; - print ''; - - print load_fiche_titre($langs->trans('DefineEventUserCP'),'',''); - - print $langs->trans('MotifCP').' : '; - print $holiday->selectEventCP(); - print '   '.$langs->trans('UserCP').' : '; - print $form->select_dolusers('', 'userCP', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300'); - print ' '; - - print '

'; -} - - $typeleaves=$holiday->getTypes(1,1); if (count($typeleaves) == 0) diff --git a/htdocs/holiday/list.php b/htdocs/holiday/list.php index 8489f57187e..013ee177726 100644 --- a/htdocs/holiday/list.php +++ b/htdocs/holiday/list.php @@ -66,6 +66,21 @@ $year_end = GETPOST('year_end'); $search_employe = GETPOST('search_employe'); $search_valideur = GETPOST('search_valideur'); $search_statut = GETPOST('select_statut'); +$type = GETPOST('type','int'); + +// List of fields to search into when doing a "search in all" +$fieldstosearchall = array( + 'cp.rowid'=>'Ref', + 'cp.description'=>'Description', + 'uu.lastname'=>'EmployeeLastname', + 'uu.firstname'=>'EmployeeFirstname' +); + + + +/* + * Actions + */ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers { @@ -79,23 +94,9 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETP $search_employe=""; $search_valideur=""; $search_statut=""; + $type=''; } -// List of fields to search into when doing a "search in all" -$fieldstosearchall = array( - 'cp.rowid'=>'Ref', - 'cp.description'=>'Description', - 'uu.lastname'=>'EmployeeLastname', - 'uu.firstname'=>'EmployeeFirstname' -); - - -/* - * Actions - */ - -// None - /* @@ -193,6 +194,8 @@ if (!empty($sall)) if (empty($user->rights->holiday->read_all)) $filter.=' AND cp.fk_user IN ('.join(',',$childids).')'; +if ($type) $filter.=' AND cp.fk_type IN ('.$type.')'; + // Récupération de l'ID de l'utilisateur $user_id = $user->id; @@ -302,12 +305,12 @@ print "\n"; // FILTRES print ''; -print ''; +print ''; print ''; print ''; // DATE CREATE -print ''; +print ''; print ''; $formother->select_year($year_create,'year_create',1, $min_year, 0); print ''; @@ -346,20 +349,29 @@ else } // Type -print ''; +print ''; +$typeleaves=$holidaystatic->getTypes(1,-1); +$arraytypeleaves=array(); +foreach($typeleaves as $key => $val) +{ + $labeltoshow = $val['label']; + //$labeltoshow .= ($val['delay'] > 0 ? ' ('.$langs->trans("NoticePeriod").': '.$val['delay'].' '.$langs->trans("days").')':''); + $arraytypeleaves[$val['rowid']]=$labeltoshow; +} +print $form->selectarray('type', $arraytypeleaves, (GETPOST('type')?GETPOST('type'):''), 1); print ''; // DUREE print ' '; // DATE DEBUT -print ''; +print ''; print ''; $formother->select_year($year_start,'year_start',1, $min_year, $max_year); print ''; // DATE FIN -print ''; +print ''; print ''; $formother->select_year($year_end,'year_end',1, $min_year, $max_year); print ''; diff --git a/htdocs/install/mysql/migration/4.0.0-5.0.0.sql b/htdocs/install/mysql/migration/4.0.0-5.0.0.sql index 122d5efefca..ccba7d295a7 100644 --- a/htdocs/install/mysql/migration/4.0.0-5.0.0.sql +++ b/htdocs/install/mysql/migration/4.0.0-5.0.0.sql @@ -36,6 +36,8 @@ ALTER TABLE llx_ecm_files ADD COLUMN gen_or_uploaded varchar(12) after cover; DROP TABLE llx_document_generator; DROP TABLE llx_ecm_documents; +DROP TABLE llx_holiday_events; +DROP TABLE llx_holiday_types; ALTER TABLE llx_notify ADD COLUMN type_target varchar(16) NULL; diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 13403a42dd9..085fadfa519 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -567,6 +567,7 @@ CanBeModifiedIfOk=Can be modified if valid CanBeModifiedIfKo=Can be modified if not valid RecordModifiedSuccessfully=Record modified successfully RecordsModified=%s records modified +RecordsDeleted=%s records deleted AutomaticCode=Automatic code FeatureDisabled=Feature disabled MoveBox=Move widget