/** * Show a HTML Tab with boxes of a particular area including personalized choices of user * * @param User $user Object User * @param String $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) */ static function printBoxesArea($user, $areacode) { global $conf, $langs, $db; include_once DOL_DOCUMENT_ROOT . '/core/class/infobox.class.php'; //$infobox=new InfoBox($db); $boxactivated = InfoBox::listboxes($db, 'activated', $areacode, $user); $arrayboxactivatedid = array(); foreach ($boxactivated as $box) { $arrayboxactivatedid[$box->id] = $box->id; } $selectboxlist = ''; if ($conf->use_javascript_ajax) { $emptyuser = new User($db); $boxavailable = InfoBox::listboxes($db, 'activated', $areacode, $emptyuser, $arrayboxactivatedid); // Available here is activated for empty user $arrayboxtoactivatelabel = array(); foreach ($boxavailable as $box) { $arrayboxtoactivatelabel[$box->id] = $box->boxlabel; } $form = new Form($db); $selectboxlist = $form->selectarray('boxcombo', $arrayboxtoactivatelabel, '', 1); } print '<script type="text/javascript" language="javascript"> jQuery(document).ready(function() { jQuery("#boxcombo").change(function() { var boxid=jQuery("#boxcombo").val(); if (boxid > 0) { var left_list = cleanSerialize(jQuery("#left").sortable("serialize")); var right_list = cleanSerialize(jQuery("#right").sortable("serialize")); var boxorder = \'A:\' + left_list + \'-B:\' + right_list; jQuery.ajax({ url: \'' . DOL_URL_ROOT . '/core/ajax/box.php?boxorder=\'+boxorder+\'&boxid=\'+boxid+\'&zone=' . $areacode . '&userid=' . $user->id . '\', async: false }); //jQuery.get(\'' . DOL_URL_ROOT . '/core/ajax/box.php?boxorder=\'+boxorder+\'&boxid=\'+boxid+\'&zone=' . $areacode . '&userid=' . $user->id . '\'); window.location.search=\'mainmenu=' . GETPOST("mainmenu") . '&leftmenu=' . GETPOST('leftmenu') . '&action=addbox&boxid=\'+boxid; //window.location.href=\'' . $_SERVER["PHP_SELF"] . '\'; } });'; if (!count($arrayboxtoactivatelabel)) { print 'jQuery("#boxcombo").hide();'; } print ' }); </script>'; print load_fiche_titre(count($boxactivated) ? $langs->trans("OtherInformationsBoxes") : '', $selectboxlist, '', '', 'otherboxes'); if (count($boxactivated)) { print '<table width="100%" class="notopnoleftnoright">'; print '<tr><td class="notopnoleftnoright">' . "\n"; print '<div class="fichehalfleft">'; print "\n<!-- Box left container -->\n"; print '<div id="left" class="connectedSortable">' . "\n"; // Define $box_max_lines $box_max_lines = 5; if (!empty($conf->global->MAIN_BOXES_MAXLINES)) { $box_max_lines = $conf->global->MAIN_BOXES_MAXLINES; } $ii = 0; foreach ($boxactivated as $key => $box) { if (preg_match('/^A/i', $box->box_order)) { $ii++; //print 'box_id '.$boxactivated[$ii]->box_id.' '; //print 'box_order '.$boxactivated[$ii]->box_order.'<br>'; // Affichage boite key $box->loadBox($box_max_lines); $box->showBox(); } } $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 '</div><div class="fichehalfright"><div class="ficheaddleft">'; print "\n<!-- Box right container -->\n"; print '<div id="right" class="connectedSortable">' . "\n"; $ii = 0; foreach ($boxactivated as $key => $box) { if (preg_match('/^B/i', $box->box_order)) { $ii++; //print 'box_id '.$boxactivated[$ii]->box_id.' '; //print 'box_order '.$boxactivated[$ii]->box_order.'<br>'; // Affichage boite key $box->loadBox($box_max_lines); $box->showBox(); } } $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 '</div></div>'; print "\n"; print "</td></tr>"; print "</table>"; if ($conf->use_javascript_ajax) { print "\n"; print '<script type="text/javascript" language="javascript">'; // For moving print 'jQuery(function() { jQuery("#left, #right").sortable({ /* placeholder: \'ui-state-highlight\', */ handle: \'.boxhandle\', revert: \'invalid\', items: \'.box\', containment: \'.fiche\', connectWith: \'.connectedSortable\', stop: function(event, ui) { updateOrder(0); } }); }); ' . "\n"; print 'function updateOrder() { var left_list = cleanSerialize(jQuery("#left").sortable("serialize")); var right_list = cleanSerialize(jQuery("#right").sortable("serialize")); var boxorder = \'A:\' + left_list + \'-B:\' + right_list; jQuery.get(\'' . DOL_URL_ROOT . '/core/ajax/box.php?boxorder=\'+boxorder+\'&zone=' . $areacode . '&userid=\'+' . $user->id . '); }' . "\n"; // For closing print 'jQuery(document).ready(function() { jQuery(".boxclose").click(function() { var self = this; // because JQuery can modify this var boxid=self.id.substring(8); jQuery(\'#boxto_\'+boxid).remove(); updateOrder(); }); });' . "\n"; print '</script>' . "\n"; } } return count($boxactivated); }
/** * Method to show box * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @return void */ function showBox($head = null, $contents = null) { parent::showBox($this->info_box_head, $this->info_box_contents); }
/** * Method to show box * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @return void */ function showBox($head = null, $contents = null) { global $langs, $conf; parent::showBox($this->info_box_head, $this->info_box_contents); if ($conf->global->SHOW_DIALOG_HOMEPAGE) { $actioncejour = false; $contents = $this->info_box_contents; $nblines = count($contents); $bcx = array(); $bcx[0] = 'class="box_pair"'; $bcx[1] = 'class="box_impair"'; if ($contents[0][0]['text'] != $langs->trans("NoActionsToDo")) { print '<div id="dialog" title="' . $nblines . " " . $langs->trans("ActionsToDo") . '">'; print '<table width=100%>'; for ($i = 0, $n = $nblines; $i < $n; $i++) { if (isset($contents[$i])) { // on affiche que les évènement du jours ou passé // qui ne sont pas à 100% $actioncejour = true; $var = !$var; // TR $logo = $contents[$i][0]['logo']; $label = $contents[$i][1]['text']; $urlevent = $contents[$i][1]['url']; $logosoc = $contents[$i][2]['logo']; $nomsoc = $contents[$i][3]['text']; $urlsoc = $contents[$i][3]['url']; $dateligne = $contents[$i][4]['text']; $percentage = $contents[$i][5]['text']; print '<tr ' . $bcx[$var] . '>'; print '<td align=center>'; print img_object("", $logo); print '</td>'; print '<td align=center><a href="' . $urlevent . '">' . $label . '</a></td>'; print '<td align=center><a href="' . $urlsoc . '">' . img_object("", $logosoc) . " " . $nomsoc . '</a></td>'; print '<td align=center>' . $dateligne . '</td>'; print '<td align=center>' . $percentage . '</td>'; print '</tr>'; } } print '</table>'; } print '</div>'; if ($actioncejour) { print '<script>'; print '$( "#dialog" ).dialog({ autoOpen: true });'; if ($conf->global->SHOW_DIALOG_HOMEPAGE > 1) { print 'setTimeout(function(){'; print '$("#dialog").dialog("close");'; print '}, ' . $conf->global->SHOW_DIALOG_HOMEPAGE * 1000 . ');'; } print '</script>'; } else { print '<script>'; print '$( "#dialog" ).dialog({ autoOpen: false });'; print '</script>'; } } }
/** * Show a HTML Tab with boxes of a particular area including personalized choices of user. * Class 'Form' must be known. * * @param User $user Object User * @param String $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) */ static function printBoxesArea($user, $areacode) { global $conf, $langs, $db; include_once DOL_DOCUMENT_ROOT . '/core/class/infobox.class.php'; $confuserzone = 'MAIN_BOXES_' . $areacode; $boxactivated = InfoBox::listBoxes($db, 'activated', $areacode, empty($user->conf->{$confuserzone}) ? null : $user); // Search boxes of common+user (or common only if user has no specific setup) $boxidactivatedforuser = array(); foreach ($boxactivated as $box) { if (empty($user->conf->{$confuserzone}) || $box->fk_user == $user->id) { $boxidactivatedforuser[$box->id] = $box->id; } // We keep only boxes to show for user } $selectboxlist = ''; $arrayboxtoactivatelabel = array(); if (!empty($user->conf->{$confuserzone})) { $boxorder = ''; $langs->load("boxes"); // Load label of boxes foreach ($boxactivated as $box) { if (!empty($boxidactivatedforuser[$box->id])) { continue; } // Already visible for user $label = $langs->transnoentitiesnoconv($box->boxlabel); if (preg_match('/graph/', $box->class)) { $label .= ' (' . $langs->trans("Graph") . ')'; } $arrayboxtoactivatelabel[$box->id] = $label; // We keep only boxes not shown for user, to show into combo list } foreach ($boxidactivatedforuser as $boxid) { if (empty($boxorder)) { $boxorder .= 'A:'; } $boxorder .= $boxid . ','; } //var_dump($boxidactivatedforuser); // Class Form must have been already loaded $selectboxlist .= '<form name="addbox" method="POST" action="' . $_SERVER["PHP_SELF"] . '">'; $selectboxlist .= '<input type="hidden" name="addbox" value="addbox">'; $selectboxlist .= '<input type="hidden" name="userid" value="' . $user->id . '">'; $selectboxlist .= '<input type="hidden" name="areacode" value="' . $areacode . '">'; $selectboxlist .= '<input type="hidden" name="boxorder" value="' . $boxorder . '">'; $selectboxlist .= Form::selectarray('boxcombo', $arrayboxtoactivatelabel, '', 1); if (empty($conf->use_javascript_ajax)) { $selectboxlist .= ' <input type="submit" class="button" value="' . $langs->trans("AddBox") . '">'; } $selectboxlist .= '</form>'; } // Javascript code for dynamic actions if (!empty($conf->use_javascript_ajax)) { print '<script type="text/javascript" language="javascript"> // To update list of activated boxes function updateBoxOrder(closing) { var left_list = cleanSerialize(jQuery("#left").sortable("serialize")); var right_list = cleanSerialize(jQuery("#right").sortable("serialize")); var boxorder = \'A:\' + left_list + \'-B:\' + right_list; if (boxorder==\'A:A-B:B\' && closing == 1) // There is no more boxes on screen, and we are after a delete of a box so we must hide title { jQuery.ajax({ url: \'' . DOL_URL_ROOT . '/core/ajax/box.php?boxorder=\'+boxorder+\'&zone=' . $areacode . '&userid=\'+' . $user->id . ', async: false }); // We force reload to be sure to get all boxes into list window.location.search=\'mainmenu=' . GETPOST("mainmenu") . '&leftmenu=' . GETPOST('leftmenu') . '&action=delbox\'; } else { jQuery.ajax({ url: \'' . DOL_URL_ROOT . '/core/ajax/box.php?boxorder=\'+boxorder+\'&zone=' . $areacode . '&userid=\'+' . $user->id . ', async: true }); } } jQuery(document).ready(function() { jQuery("#boxcombo").change(function() { var boxid=jQuery("#boxcombo").val(); if (boxid > 0) { var left_list = cleanSerialize(jQuery("#left").sortable("serialize")); var right_list = cleanSerialize(jQuery("#right").sortable("serialize")); var boxorder = \'A:\' + left_list + \'-B:\' + right_list; jQuery.ajax({ url: \'' . DOL_URL_ROOT . '/core/ajax/box.php?boxorder=\'+boxorder+\'&boxid=\'+boxid+\'&zone=' . $areacode . '&userid=' . $user->id . '\', async: false }); window.location.search=\'mainmenu=' . GETPOST("mainmenu") . '&leftmenu=' . GETPOST('leftmenu') . '&action=addbox&boxid=\'+boxid; } });'; if (!count($arrayboxtoactivatelabel)) { print 'jQuery("#boxcombo").hide();'; } print ' jQuery("#left, #right").sortable({ /* placeholder: \'ui-state-highlight\', */ handle: \'.boxhandle\', revert: \'invalid\', items: \'.box\', containment: \'.fiche\', connectWith: \'.connectedSortable\', stop: function(event, ui) { updateBoxOrder(0); } }); jQuery(".boxclose").click(function() { var self = this; // because JQuery can modify this var boxid=self.id.substring(8); var label=jQuery(\'#boxlabelentry\'+boxid).val(); jQuery(\'#boxto_\'+boxid).remove(); if (boxid > 0) jQuery(\'#boxcombo\').append(new Option(label, boxid)); updateBoxOrder(1); }); });' . "\n"; print '</script>' . "\n"; } $nbboxactivated = count($boxidactivatedforuser); print load_fiche_titre($nbboxactivated ? $langs->trans("OtherInformationsBoxes") : '', $selectboxlist, '', '', 'otherboxes'); if ($nbboxactivated) { $langs->load("boxes"); $langs->load("projects"); $emptybox = new ModeleBoxes($db); print '<table width="100%" class="notopnoleftnoright">'; print '<tr><td class="notopnoleftnoright">' . "\n"; print '<div class="fichehalfleft">'; print "\n<!-- Box left container -->\n"; print '<div id="left" class="connectedSortable">' . "\n"; // Define $box_max_lines $box_max_lines = 5; if (!empty($conf->global->MAIN_BOXES_MAXLINES)) { $box_max_lines = $conf->global->MAIN_BOXES_MAXLINES; } $ii = 0; foreach ($boxactivated as $key => $box) { if (!empty($user->conf->{$confuserzone}) && $box->fk_user == 0 || empty($user->conf->{$confuserzone}) && $box->fk_user != 0) { continue; } if (empty($box->box_order) && $ii < $nbboxactivated / 2) { $box->box_order = 'A' . sprintf("%02d", $ii + 1); } // When box_order was not yet set to Axx or Bxx and is still 0 if (preg_match('/^A/i', $box->box_order)) { $ii++; //print 'box_id '.$boxactivated[$ii]->box_id.' '; //print 'box_order '.$boxactivated[$ii]->box_order.'<br>'; // Affichage boite key $box->loadBox($box_max_lines); $box->showBox(); } } if (empty($conf->browser->phone)) { $emptybox->box_id = 'A'; $emptybox->info_box_head = array(); $emptybox->info_box_contents = array(); $emptybox->showBox(array(), array()); } print "</div>\n"; print "<!-- End box left container -->\n"; print '</div><div class="fichehalfright"><div class="ficheaddleft">'; print "\n<!-- Box right container -->\n"; print '<div id="right" class="connectedSortable">' . "\n"; $ii = 0; foreach ($boxactivated as $key => $box) { if (!empty($user->conf->{$confuserzone}) && $box->fk_user == 0 || empty($user->conf->{$confuserzone}) && $box->fk_user != 0) { continue; } if (empty($box->box_order) && $ii < $nbboxactivated / 2) { $box->box_order = 'B' . sprintf("%02d", $ii + 1); } // When box_order was not yet set to Axx or Bxx and is still 0 if (preg_match('/^B/i', $box->box_order)) { $ii++; //print 'box_id '.$boxactivated[$ii]->box_id.' '; //print 'box_order '.$boxactivated[$ii]->box_order.'<br>'; // Affichage boite key $box->loadBox($box_max_lines); $box->showBox(); } } if (empty($conf->browser->phone)) { $emptybox->box_id = 'B'; $emptybox->info_box_head = array(); $emptybox->info_box_contents = array(); $emptybox->showBox(array(), array()); } print "</div>\n"; print "<!-- End box right container -->\n"; print '</div></div>'; print "\n"; print "</td></tr>"; print "</table>"; } return count($boxactivated); }
// $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_param"; // $sql.= " WHERE param LIKE 'MAIN_BOXES_%'"; // $resql = $db->query($sql); $sql = "DELETE FROM " . MAIN_DB_PREFIX . "boxes"; $sql .= " WHERE entity = " . $conf->entity; $sql .= " AND box_id=" . $obj->box_id; $resql = $db->query($sql); $db->commit(); } } if ($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"]); $resultupdatefrom = 0; $resultupdateto = 0; if (is_object($objfrom) && is_object($objto)) { $newfirst = $objto->box_order; $newsecond = $objfrom->box_order; if ($newfirst == $newsecond) { $newsecondchar = preg_replace('/[0-9]+/', '', $newsecond); $newsecondnum = preg_replace('/[a-zA-Z]+/', '', $newsecond); $newsecond = sprintf("%s%02d", $newsecondchar ? $newsecondchar : 'A', $newsecondnum + 1); } $sql = "UPDATE " . MAIN_DB_PREFIX . "boxes SET box_order='" . $newfirst . "' WHERE rowid=" . $objfrom->rowid; dol_syslog($sql); $resultupdatefrom = $db->query($sql); if (!$resultupdatefrom) {
/** * Method to show box. Called by Dolibarr eatch time it wants to display the box. * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @return void */ public function showBox($head = null, $contents = null) { // You may make your own code here… // … or use the parent's class function using the provided head and contents templates parent::showBox($this->info_box_head, $this->info_box_contents); }
/** * Show a HTML Tab with boxes of a particular area including personalized choices of user * * @param User $user Object User * @param String $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 (count($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" class="notopnoleft" style="padding-right: 8px;">'."\n"; print "\n<!-- Box left container -->\n"; print '<div id="left" class="connectedSortable">'."\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" class="connectedSortable">'."\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 'jQuery(function() { jQuery("#left, #right").sortable({ /* placeholder: \'ui-state-highlight\', */ handle: \'.boxhandle\', revert: \'invalid\', items: \'.box\', containment: \'.fiche\', connectWith: \'.connectedSortable\', stop: function(event, ui) { updateOrder(); } }); }); '; print "\n"; print 'function updateOrder(){'."\n"; print 'var left_list = cleanSerialize(jQuery("#left").sortable( "serialize" ));'."\n"; print 'var right_list = cleanSerialize(jQuery("#right").sortable( "serialize" ));'."\n"; print 'var boxorder = \'A:\' + left_list + \'-B:\' + right_list;'."\n"; //print 'alert( \'boxorder=\' + boxorder );'; print 'var userid = \''.$user->id.'\';'."\n"; print 'jQuery.get(\'core/ajaxbox.php?boxorder=\'+boxorder+\'&userid=\'+'.$user->id.');'."\n"; print '}'."\n"; print '</script>'."\n"; } } return count($boxarray); }