Boxes area output is now in a function.

Contracts boxes show status of each services (status of contracts is deprecated).
This commit is contained in:
Laurent Destailleur 2010-04-20 18:23:55 +00:00
parent 56942f72d1
commit e1c01ac3c8
6 changed files with 233 additions and 199 deletions

View File

@ -20,7 +20,7 @@
/**
* \file htdocs/admin/boxes.php
* \brief Page d'administration/configuration des boites
* \brief Page to setup boxes
* \version $Id$
*/
@ -53,7 +53,7 @@ if ($_POST["action"] == 'add')
$sql.= " WHERE fk_user = 0";
$sql.= " AND box_id = ".$_POST["boxid"];
$sql.= " AND position = ".$_POST["pos"];
$resql = $db->query($sql);
dol_syslog("boxes.php::search if box active sql=".$sql);
if ($resql)
@ -62,7 +62,7 @@ if ($_POST["action"] == 'add')
if ($num == 0)
{
$db->begin();
// Si la boite n'est pas deja active, insert with box_order=''
$sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes (";
$sql.= "box_id";
@ -75,10 +75,10 @@ if ($_POST["action"] == 'add')
$sql.= ", ''";
$sql.= ", 0";
$sql.= ")";
dol_syslog("boxes.php activate box sql=".$sql);
$resql = $db->query($sql);
// Remove all personalized setup when a box is activated or disabled
$sql = "DELETE FROM ".MAIN_DB_PREFIX."user_param";
$sql.= " WHERE param LIKE 'MAIN_BOXES_%'";
@ -87,7 +87,7 @@ if ($_POST["action"] == 'add')
$db->commit();
}
Header("Location: boxes.php");
exit;
}
@ -100,11 +100,11 @@ if ($_POST["action"] == 'add')
if ($_GET["action"] == 'delete')
{
$db->begin();
$sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes";
$sql.= " WHERE rowid=".$_GET["rowid"];
$resql = $db->query($sql);
// Remove all personalized setup when a box is activated or disabled
$sql = "DELETE FROM ".MAIN_DB_PREFIX."user_param";
$sql.= " WHERE param LIKE 'MAIN_BOXES_%'";
@ -117,13 +117,13 @@ if ($_GET["action"] == 'switch')
{
// On permute les valeur du champ box_order des 2 lignes de la table boxes
$db->begin();
$objfrom=new ModeleBoxes($db);
$objfrom->fetch($_GET["switchfrom"]);
$objto=new ModeleBoxes($db);
$objto->fetch($_GET["switchto"]);
if (is_object($objfrom) && is_object($objto))
{
$sql="UPDATE ".MAIN_DB_PREFIX."boxes set box_order='".$objto->box_order."' WHERE rowid=".$objfrom->rowid;
@ -135,7 +135,7 @@ if ($_GET["action"] == 'switch')
$resultupdateto = $db->query($sql);
if (! $resultupdateto) { dol_print_error($db); }
}
if ($resultupdatefrom && $resultupdateto)
{
$db->commit();
@ -180,7 +180,7 @@ if ($resql)
$obj = $db->fetch_object($resql);
$boxes[$obj->position][$obj->box_id]=1;
$i++;
array_push($actives,$obj->box_id);
if ($obj->box_order == '' || $obj->box_order == '0' || $decalage) $decalage++;
@ -266,15 +266,15 @@ $var=True;
if ($resql)
{
$html=new Form($db);
$num = $db->num_rows($resql);
$i = 0;
// Boucle sur toutes les boites
while ($i < $num)
{
$obj = $db->fetch_object($resql);
if (preg_match('/^([^@]+)@([^@]+)$/i',$obj->file,$regs))
{
$module = $regs[1];
@ -285,10 +285,10 @@ if ($resql)
$module=preg_replace('/.php$/i','',$obj->file);
$sourcefile = "/includes/boxes/".$module.".php";
}
include_once(DOL_DOCUMENT_ROOT.$sourcefile);
$box=new $module($db,$obj->note);
// if (in_array($obj->rowid, $actives) && $box->box_multiple <> 1)
if (in_array($obj->rowid, $actives))
{
@ -297,7 +297,7 @@ if ($resql)
else
{
$var = ! $var;
if (preg_match('/^([^@]+)@([^@]+)$/i',$box->boximg))
{
$logo = $box->boximg;
@ -306,14 +306,14 @@ if ($resql)
{
$logo=preg_replace("/^object_/i","",$box->boximg);
}
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<tr '.$bc[$var].'>';
print '<td>'.img_object("",$logo).' '.$box->boxlabel.'</td>';
print '<td>' . ($obj->note?$obj->note:'&nbsp;') . '</td>';
print '<td>' . $sourcefile . '</td>';
// Pour chaque position possible, on affiche un lien
// d'activation si boite non deja active pour cette position
print '<td align="center">';
@ -322,12 +322,12 @@ if ($resql)
print '<input type="hidden" name="boxid" value="'.$obj->rowid.'">';
print ' <input type="submit" class="button" name="button" value="'.$langs->trans("Activate").'">';
print '</td>';
print '</tr></form>';
}
$i++;
}
$db->free($resql);
}
@ -365,18 +365,18 @@ if ($resql)
$num = $db->num_rows($resql);
$i = 0;
$var=true;
$box_order=1;
$foundrupture=1;
// On lit avec un coup d'avance
$obj = $db->fetch_object($resql);
while ($obj && $i < $num)
{
$var = ! $var;
$objnext = $db->fetch_object($resql);
if (preg_match('/^([^@]+)@([^@]+)$/i',$obj->file,$regs))
{
$module = $regs[1];
@ -387,10 +387,10 @@ if ($resql)
$module=preg_replace('/.php$/i','',$obj->file);
$sourcefile = "/includes/boxes/".$module.".php";
}
include_once(DOL_DOCUMENT_ROOT.$sourcefile);
$box=new $module($db,$obj->note);
if (preg_match('/^([^@]+)@([^@]+)$/i',$box->boximg))
{
$logo = $box->boximg;
@ -399,7 +399,7 @@ if ($resql)
{
$logo=preg_replace("/^object_/i","",$box->boximg);
}
print '<tr '.$bc[$var].'>';
print '<td>'.img_object("",$logo).' '.$box->boxlabel.'</td>';
print '<td>' . ($obj->note?$obj->note:'&nbsp;') . '</td>';
@ -416,17 +416,17 @@ if ($resql)
print '<td align="center">';
print '<a href="boxes.php?rowid='.$obj->rowid.'&amp;action=delete">'.img_delete().'</a>';
print '</td>';
print "</tr>\n";
$i++;
$box_order++;
if (! $foundrupture) $objprevious = $obj;
else $box_order=1;
$obj=$objnext;
}
$db->free($resql);
}

View File

@ -28,6 +28,149 @@
/**
* \brief Show a HTML Tab with boxes of a particular area including personalized choices of user
* \param user User
* \param areacode Code of area for pages (0=value for Home page)
* \return int <0 if KO, Nb of boxes shown of OK (0 to n)
*/
function printBoxesArea($user,$areacode)
{
global $conf,$langs,$db;
$infobox=new InfoBox($db);
$boxarray=$infobox->listboxes($areacode,$user);
//$boxid_left = array();
//$boxid_right = array();
if (sizeof($boxarray))
{
print_fiche_titre($langs->trans("OtherInformationsBoxes"),'','','','otherboxes');
print '<table width="100%" class="notopnoleftnoright">';
print '<tr><td class="notopnoleftnoright">'."\n";
print '<table width="100%" style="border-collapse: collapse; border: 0px; margin: 0px; padding: 0px;"><tr>';
// Affichage colonne gauche
print '<td width="50%" valign="top">'."\n";
print "\n<!-- Box left container -->\n";
print '<div id="left">'."\n";
$ii=0;
foreach ($boxarray as $key => $box)
{
if (preg_match('/^A/i',$box->box_order)) // column A
{
$ii++;
//print 'box_id '.$boxarray[$ii]->box_id.' ';
//print 'box_order '.$boxarray[$ii]->box_order.'<br>';
//$boxid_left[$key] = $box->box_id;
// Affichage boite key
$box->loadBox($conf->box_max_lines);
$box->showBox();
}
}
// If no box on left, we add an invisible empty box
if ($ii==0)
{
$emptybox=new ModeleBoxes($db);
$emptybox->box_id='A';
$emptybox->info_box_head=array();
$emptybox->info_box_contents=array();
$emptybox->showBox(array(),array());
}
print "</div>\n";
print "<!-- End box container -->\n";
print "</td>\n";
// Affichage colonne droite
print '<td width="50%" valign="top">';
print "\n<!-- Box right container -->\n";
print '<div id="right">'."\n";
$ii=0;
foreach ($boxarray as $key => $box)
{
if (preg_match('/^B/i',$box->box_order)) // colonne B
{
$ii++;
//print 'box_id '.$boxarray[$ii]->box_id.' ';
//print 'box_order '.$boxarray[$ii]->box_order.'<br>';
//$boxid_right[$key] = $boxarray[$key]->box_id;
// Affichage boite key
$box->loadBox($conf->box_max_lines);
$box->showBox();
}
}
// If no box on right, we show add an invisible empty box
if ($ii==0)
{
$emptybox=new ModeleBoxes($db);
$emptybox->box_id='B';
$emptybox->info_box_head=array();
$emptybox->info_box_contents=array();
$emptybox->showBox(array(),array());
}
print "</div>\n";
print "<!-- End box container -->\n";
print "</td>";
print "</tr></table>\n";
print "\n";
print "</td></tr>";
print "</table>";
if ($conf->use_javascript_ajax)
{
print "\n";
print '<script type="text/javascript" language="javascript">';
print 'function updateOrder(){';
print 'var left_list = cleanSerialize(Sortable.serialize(\'left\'));';
print 'var right_list = cleanSerialize(Sortable.serialize(\'right\'));';
print 'var boxorder = \'A:\' + left_list + \'-B:\' + right_list;';
//alert( \'boxorder=\' + boxorder );
print 'var userid = \''.$user->id.'\';';
print 'var url = "ajaxbox.php";';
print 'o_options = new Object();';
print 'o_options = {asynchronous:true,method: \'get\',parameters: \'boxorder=\' + boxorder + \'&userid=\' + userid};';
print 'var myAjax = new Ajax.Request(url, o_options);';
print '}';
print "\n";
print '// <![CDATA['."\n";
print 'Sortable.create(\'left\', {'."\n";
print ' tag:\'div\', '."\n";
print ' containment:["left","right"], '."\n";
print ' constraint:false, '."\n";
print " handle: 'boxhandle',"."\n";
print ' onUpdate:updateOrder';
print " });\n";
print 'Sortable.create(\'right\', {'."\n";
print ' tag:\'div\', '."\n";
print ' containment:["right","left"], '."\n";
print ' constraint:false, '."\n";
print " handle: 'boxhandle',"."\n";
print ' onUpdate:updateOrder';
print " });\n";
print '// ]]>'."\n";
print '</script>'."\n";
}
}
return sizeof($boxarray);
}
/**
* \class InfoBox
* \brief Classe permettant la gestion des boxes sur une page
@ -80,7 +223,7 @@ class InfoBox
while ($j < $num)
{
$obj = $this->db->fetch_object($result);
if (preg_match('/^([^@]+)@([^@]+)$/i',$obj->file,$regs))
{
$module = $regs[1];
@ -91,10 +234,10 @@ class InfoBox
$module=preg_replace('/.php$/i','',$obj->file);
$sourcefile = "/includes/boxes/".$module.".php";
}
include_once(DOL_DOCUMENT_ROOT.$sourcefile);
$box=new $module($db,$obj->note);
$box->rowid=$obj->rowid;
$box->box_id=$obj->box_id;
$box->position=$obj->position;
@ -140,7 +283,7 @@ class InfoBox
while ($j < $num)
{
$obj = $this->db->fetch_object($result);
if (preg_match('/^([^@]+)@([^@]+)$/i',$obj->file,$regs))
{
$module = $regs[1];
@ -151,10 +294,10 @@ class InfoBox
$module=preg_replace('/.php$/i','',$obj->file);
$sourcefile = "/includes/boxes/".$module.".php";
}
include_once(DOL_DOCUMENT_ROOT.$sourcefile);
$box=new $module($db,$obj->note);
$box->rowid=$obj->rowid;
$box->box_id=$obj->box_id;
$box->position=$obj->position;
@ -287,5 +430,10 @@ class InfoBox
return -1;
}
}
}
?>

View File

@ -5,7 +5,7 @@
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@ -1075,12 +1075,16 @@ class Contrat extends CommonObject
if ($statut == 1) { return img_picto($langs->trans('ContractStatusValidated'),'statut4'); }
if ($statut == 2) { return img_picto($langs->trans('ContractStatusClosed'),'statut6'); }
}
if ($mode == 4)
if ($mode == 4 || $mode == 6)
{
$line=new ContratLigne($this->db);
$text=($this->nbofserviceswait+$this->nbofservicesopened+$this->nbofservicesexpired+$this->nbofservicesclosed);
$text.=' '.$langs->trans("Services");
$text.=': &nbsp; &nbsp; ';
$text='';
if ($mode == 4)
{
$text=($this->nbofserviceswait+$this->nbofservicesopened+$this->nbofservicesexpired+$this->nbofservicesclosed);
$text.=' '.$langs->trans("Services");
$text.=': &nbsp; &nbsp; ';
}
$text.=$this->nbofserviceswait.' '.$line->LibStatut(0,3).' &nbsp; ';
$text.=$this->nbofservicesopened.' '.$line->LibStatut(4,3,0).' &nbsp; ';
$text.=$this->nbofservicesexpired.' '.$line->LibStatut(4,3,1).' &nbsp; ';

View File

@ -46,9 +46,9 @@ class box_contracts extends ModeleBoxes {
function box_contracts()
{
global $langs;
$langs->load("contracts");
$this->boxlabel=$langs->trans("BoxLastContracts");
}
@ -64,15 +64,14 @@ class box_contracts extends ModeleBoxes {
include_once(DOL_DOCUMENT_ROOT."/contrat/contrat.class.php");
$contractstatic=new Contrat($db);
$this->info_box_head = array('text' => $langs->trans("BoxTitleLastContracts",$max));
if ($user->rights->contrat->lire)
{
$sql = "SELECT s.nom, s.rowid as socid,";
$sql.= " c.rowid, c.ref, c.statut as fk_statut, c.date_contrat, c.datec, c.fin_validite, c.date_cloture";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql.= ", ".MAIN_DB_PREFIX."contrat as c";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE c.fk_soc = s.rowid";
$sql.= " AND c.entity = ".$conf->entity;
@ -80,52 +79,59 @@ class box_contracts extends ModeleBoxes {
if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
$sql.= " ORDER BY c.date_contrat DESC, c.ref DESC ";
$sql.= $db->plimit($max, 0);
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows($result);
$now=gmmktime();
$i = 0;
while ($i < $num)
{
$objp = $db->fetch_object($result);
$datec=$db->jdate($objp->datec);
$dateterm=$db->jdate($objp->fin_validite);
$dateclose=$db->jdate($objp->date_cloture);
$late = '';
if ($objp->fk_statut == 1 && $dateterm < ($now - $conf->contrat->cloture->warning_delay)) { $late = img_warning($langs->trans("Late")); }
$contractstatic->statut=$objp->fk_statut;
$contractstatic->id=$objp->rowid;
$result=$contractstatic->fetch_lignes();
// fin_validite is no more on contract but on services
// if ($objp->fk_statut == 1 && $dateterm < ($now - $conf->contrat->cloture->warning_delay)) { $late = img_warning($langs->trans("Late")); }
$this->info_box_contents[$i][0] = array('td' => 'align="left" width="16"',
'logo' => $this->boximg,
'url' => DOL_URL_ROOT."/contrat/fiche.php?id=".$objp->rowid);
$this->info_box_contents[$i][1] = array('td' => 'align="left"',
'text' => $objp->ref,
'text' => ($objp->ref?$objp->ref:$objp->rowid), // Some contracts have no ref
'text2'=> $late,
'url' => DOL_URL_ROOT."/contrat/fiche.php?id=".$objp->rowid);
$this->info_box_contents[$i][2] = array('td' => 'align="left" width="16"',
'logo' => 'company',
'url' => DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->socid);
$this->info_box_contents[$i][3] = array('td' => 'align="left"',
'text' => dol_trunc($objp->nom,40),
'url' => DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->socid);
$this->info_box_contents[$i][4] = array('td' => 'align="right"',
'text' => dol_print_date($datec,'day'));
$this->info_box_contents[$i][5] = array('td' => 'align="right" width="18"',
'text' => $contractstatic->LibStatut($objp->fk_statut,3));
$this->info_box_contents[$i][5] = array('td' => 'align="right" nowrap="nowrap"',
'text' => $contractstatic->getLibStatut(6),
'asis'=>1
);
$i++;
}
if ($num==0) $this->info_box_contents[$i][0] = array('td' => 'align="center"','text'=>$langs->trans("NoRecordedContracts"));
}
else

View File

@ -90,7 +90,7 @@ class ModeleBoxes
/**
* \brief Methode standard d'affichage des boites
* \brief Standard method to show a box (usage by boxes not mandatory, a box can still use its own function)
* \param $head tableau des caracteristiques du titre
* \param $contents tableau des lignes de contenu
*/
@ -186,7 +186,8 @@ class ModeleBoxes
print '<td'.$tdparam.'>';
// Url
if (! empty($contents[$i][$j]['url'])) {
if (! empty($contents[$i][$j]['url']))
{
print '<a href="'.$contents[$i][$j]['url'].'" title="'.$textewithnotags.'"';
//print ' alt="'.$textewithnotags.'"'; // Pas de alt sur un "<a href>"
print isset($contents[$i][$j]['target'])?' target="'.$contents[$i][$j]['target'].'"':'';
@ -204,13 +205,13 @@ class ModeleBoxes
if (! empty($contents[$i][$j]['maxlength'])) $maxlength=$contents[$i][$j]['maxlength'];
if ($maxlength) $textewithnotags=dol_trunc($textewithnotags,$maxlength);
if (preg_match('/^<img/i',$texte)) print $texte; // show text with no html cleaning
if (preg_match('/^<img/i',$texte) || $contents[$i][$j]['asis']) print $texte; // show text with no html cleaning
else print $textewithnotags; // show text with html cleaning
// End Url
if (! empty($contents[$i][$j]['url'])) print '</a>';
if (preg_match('/^<img/i',$texte2)) print $texte2; // show text with no html cleaning
if (preg_match('/^<img/i',$texte2 || $contents[$i][$j]['asis2'])) print $texte2; // show text with no html cleaning
else print $texte2withnotags; // show text with html cleaning
print "</td>";

View File

@ -560,140 +560,15 @@ if ($nboflate > 0)
}
print '</td></tr></table>';
print '<br>';
/*
* Show boxes
*/
$infobox=new InfoBox($db);
$boxarray=$infobox->listboxes("0",$user); // 0=value for home page
//$boxid_left = array();
//$boxid_right = array();
printBoxesArea($user,"0");
if (sizeof($boxarray))
{
print '<br>';
print_fiche_titre($langs->trans("OtherInformationsBoxes"),'','','','otherboxes');
print '<table width="100%" class="notopnoleftnoright">';
print '<tr><td class="notopnoleftnoright">'."\n";
print '<table width="100%" style="border-collapse: collapse; border: 0px; margin: 0px; padding: 0px;"><tr>';
// Affichage colonne gauche
print '<td width="50%" valign="top">'."\n";
print "\n<!-- Box left container -->\n";
print '<div id="left">'."\n";
$ii=0;
foreach ($boxarray as $key => $box)
{
if (preg_match('/^A/i',$box->box_order)) // column A
{
$ii++;
//print 'box_id '.$boxarray[$ii]->box_id.' ';
//print 'box_order '.$boxarray[$ii]->box_order.'<br>';
//$boxid_left[$key] = $box->box_id;
// Affichage boite key
$box->loadBox($conf->box_max_lines);
$box->showBox();
}
}
// If no box on left, we add an invisible empty box
if ($ii==0)
{
$emptybox=new ModeleBoxes($db);
$emptybox->box_id='A';
$emptybox->info_box_head=array();
$emptybox->info_box_contents=array();
$emptybox->showBox(array(),array());
}
print "</div>\n";
print "<!-- End box container -->\n";
print "</td>\n";
// Affichage colonne droite
print '<td width="50%" valign="top">';
print "\n<!-- Box right container -->\n";
print '<div id="right">'."\n";
$ii=0;
foreach ($boxarray as $key => $box)
{
if (preg_match('/^B/i',$box->box_order)) // colonne B
{
$ii++;
//print 'box_id '.$boxarray[$ii]->box_id.' ';
//print 'box_order '.$boxarray[$ii]->box_order.'<br>';
//$boxid_right[$key] = $boxarray[$key]->box_id;
// Affichage boite key
$box->loadBox($conf->box_max_lines);
$box->showBox();
}
}
// If no box on right, we show add an invisible empty box
if ($ii==0)
{
$emptybox=new ModeleBoxes($db);
$emptybox->box_id='B';
$emptybox->info_box_head=array();
$emptybox->info_box_contents=array();
$emptybox->showBox(array(),array());
}
print "</div>\n";
print "<!-- End box container -->\n";
print "</td>";
print "</tr></table>\n";
print "\n";
print "</td></tr>";
print "</table>";
if ($conf->use_javascript_ajax)
{
print "\n";
print '<script type="text/javascript" language="javascript">';
print 'function updateOrder(){';
print 'var left_list = cleanSerialize(Sortable.serialize(\'left\'));';
print 'var right_list = cleanSerialize(Sortable.serialize(\'right\'));';
print 'var boxorder = \'A:\' + left_list + \'-B:\' + right_list;';
//alert( \'boxorder=\' + boxorder );
print 'var userid = \''.$user->id.'\';';
print 'var url = "ajaxbox.php";';
print 'o_options = new Object();';
print 'o_options = {asynchronous:true,method: \'get\',parameters: \'boxorder=\' + boxorder + \'&userid=\' + userid};';
print 'var myAjax = new Ajax.Request(url, o_options);';
print '}';
print "\n";
print '// <![CDATA['."\n";
print 'Sortable.create(\'left\', {'."\n";
print ' tag:\'div\', '."\n";
print ' containment:["left","right"], '."\n";
print ' constraint:false, '."\n";
print " handle: 'boxhandle',"."\n";
print ' onUpdate:updateOrder';
print " });\n";
print 'Sortable.create(\'right\', {'."\n";
print ' tag:\'div\', '."\n";
print ' containment:["right","left"], '."\n";
print ' constraint:false, '."\n";
print " handle: 'boxhandle',"."\n";
print ' onUpdate:updateOrder';
print " });\n";
print '// ]]>'."\n";
print '</script>'."\n";
}
}
/*