コード例 #1
0
    /**
     * 	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);
    }
コード例 #2
0
ファイル: boxes.php プロジェクト: ADDAdev/Dolibarr
    // Pour chaque position possible, on affiche un lien d'activation si boite non deja active pour cette position
    print '<td class="center">';
    print $form->selectarray("boxid[" . $box->box_id . "][pos]", $pos_name, 0, 1, 0, 0, '', 1) . "\n";
    print '<input type="hidden" name="boxid[' . $box->box_id . '][value]" value="' . $box->box_id . '">' . "\n";
    //print '<input type="checkbox" class="flat" name="boxid['.$box->box_id.'][active]">'."\n";
    print '</td>';
    print '</tr>' . "\n";
}
print '</table>' . "\n";
print '<div class="right">';
print '<input type="submit" class="button"' . (count($boxtoadd) ? '' : ' disabled="disabled"') . ' value="' . $langs->trans("Activate") . '">';
print '</div>' . "\n";
print '</form>';
print "\n" . '<!-- End Boxes Available -->' . "\n";
// Activated boxes
$boxactivated = InfoBox::listBoxes($db, 'activated', -1, null);
//var_dump($boxactivated);
print "<br>\n\n";
print_titre($langs->trans("BoxesActivated"));
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td width="300">' . $langs->trans("Box") . '</td>';
print '<td>' . $langs->trans("Note") . '/' . $langs->trans("Parameters") . '</td>';
print '<td align="center" width="160">' . $langs->trans("ActiveOn") . '</td>';
print '<td align="center" width="60" colspan="2">' . $langs->trans("PositionByDefault") . '</td>';
print '<td align="center" width="80">' . $langs->trans("Disable") . '</td>';
print '</tr>' . "\n";
$var = true;
$box_order = 1;
$foundrupture = 1;
foreach ($boxactivated as $key => $box) {