コード例 #1
0
 /**
  * Adds boxes
  *
  * @param   string  $option Options when disabling module ('newboxdefonly'=insert only boxes definition)
  *
  * @return  int             Error count (0 if OK)
  */
 function insert_boxes($option = '')
 {
     require_once DOL_DOCUMENT_ROOT . '/core/class/infobox.class.php';
     global $conf;
     $err = 0;
     if (is_array($this->boxes)) {
         $pos_name = InfoBox::getListOfPagesForBoxes();
         foreach ($this->boxes as $key => $value) {
             $file = isset($this->boxes[$key]['file']) ? $this->boxes[$key]['file'] : '';
             $note = isset($this->boxes[$key]['note']) ? $this->boxes[$key]['note'] : '';
             $enabledbydefaulton = isset($this->boxes[$key]['enabledbydefaulton']) ? $this->boxes[$key]['enabledbydefaulton'] : 'Home';
             if (empty($file)) {
                 $file = isset($this->boxes[$key][1]) ? $this->boxes[$key][1] : '';
             }
             // For backward compatibility
             if (empty($note)) {
                 $note = isset($this->boxes[$key][2]) ? $this->boxes[$key][2] : '';
             }
             // For backward compatibility
             // Search if boxes def already present
             $sql = "SELECT count(*) as nb FROM " . MAIN_DB_PREFIX . "boxes_def";
             $sql .= " WHERE file = '" . $this->db->escape($file) . "'";
             $sql .= " AND entity = " . $conf->entity;
             if ($note) {
                 $sql .= " AND note ='" . $this->db->escape($note) . "'";
             }
             dol_syslog(get_class($this) . "::insert_boxes", LOG_DEBUG);
             $result = $this->db->query($sql);
             if ($result) {
                 $obj = $this->db->fetch_object($result);
                 if ($obj->nb == 0) {
                     $this->db->begin();
                     if (!$err) {
                         $sql = "INSERT INTO " . MAIN_DB_PREFIX . "boxes_def (file, entity, note)";
                         $sql .= " VALUES ('" . $this->db->escape($file) . "', ";
                         $sql .= $conf->entity . ", ";
                         $sql .= $note ? "'" . $this->db->escape($note) . "'" : "null";
                         $sql .= ")";
                         dol_syslog(get_class($this) . "::insert_boxes", LOG_DEBUG);
                         $resql = $this->db->query($sql);
                         if (!$resql) {
                             $err++;
                         }
                     }
                     if (!$err && !preg_match('/newboxdefonly/', $option)) {
                         $lastid = $this->db->last_insert_id(MAIN_DB_PREFIX . "boxes_def", "rowid");
                         foreach ($pos_name as $key2 => $val2) {
                             //print 'key2='.$key2.'-val2='.$val2."<br>\n";
                             if ($enabledbydefaulton && $val2 != $enabledbydefaulton) {
                                 continue;
                             }
                             // Not enabled by default onto this page.
                             $sql = "INSERT INTO " . MAIN_DB_PREFIX . "boxes (box_id,position,box_order,fk_user,entity)";
                             $sql .= " VALUES (" . $lastid . ", " . $key2 . ", '0', 0, " . $conf->entity . ")";
                             dol_syslog(get_class($this) . "::insert_boxes onto page " . $key2 . "=" . $val2 . "", LOG_DEBUG);
                             $resql = $this->db->query($sql);
                             if (!$resql) {
                                 $err++;
                             }
                         }
                     }
                     if (!$err) {
                         $this->db->commit();
                     } else {
                         $this->error = $this->db->lasterror();
                         $this->db->rollback();
                     }
                 }
                 // else box already registered into database
             } else {
                 $this->error = $this->db->lasterror();
                 $err++;
             }
         }
     }
     return $err;
 }
コード例 #2
0
ファイル: boxes.php プロジェクト: ADDAdev/Dolibarr
 *   \file       htdocs/admin/boxes.php
 *   \brief      Page to setup boxes
 */
require '../main.inc.php';
include_once DOL_DOCUMENT_ROOT . '/core/boxes/modules_boxes.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/infobox.class.php';
include_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
$langs->load("admin");
$langs->load("boxes");
if (!$user->admin) {
    accessforbidden();
}
$rowid = GETPOST('rowid', 'int');
$action = GETPOST('action', 'alpha');
// Define possible position of boxes
$pos_name = InfoBox::getListOfPagesForBoxes();
$boxes = array();
/*
 * Actions
 */
if ($action == 'addconst') {
    dolibarr_set_const($db, "MAIN_BOXES_MAXLINES", $_POST["MAIN_BOXES_MAXLINES"], '', 0, '', $conf->entity);
}
if ($action == 'add') {
    $error = 0;
    $db->begin();
    if (isset($_POST['boxid']) && is_array($_POST['boxid'])) {
        foreach ($_POST['boxid'] as $boxid) {
            if (is_numeric($boxid['pos']) && $boxid['pos'] >= 0) {
                $pos = $boxid['pos'];
                // Initialize distinct fkuser with all already existing values of fk_user (user that use a personalized view of boxes for page "pos")