Exemplo n.º 1
0
    /**
     * add a notification record
     * its a bit different from standart create because it updated the record
     * on key dupliaction
     *
     * @param  array $p associative array with table field values
     * @return int   created id
     */
    public static function add($p)
    {
        static::validateParamTypes($p);
        //prepare params
        $params = array(empty($p['object_id']) ? null : $p['object_id'], empty($p['action_id']) ? null : $p['action_id'], empty($p['action_type']) ? null : $p['action_type'], empty($p['from_user_id']) ? null : $p['from_user_id'], empty($p['user_id']) ? null : $p['user_id'], empty($p['email_sent']) ? 0 : $p['email_sent']);
        //add database record
        $sql = 'INSERT INTO `' . static::getTableName() . '` (
            object_id
            ,action_id
            ,action_ids
            ,action_type
            ,from_user_id
            ,user_id
            ,email_sent
            )
            VALUES($1, $2, $2, $3, $4, $5, $6)

            ON DUPLICATE KEY

            UPDATE
            action_id = $2
            ,action_ids = CASE WHEN `read` = 1 THEN $2 ELSE CONCAT($2, \',\', action_ids) END
            ,email_sent = $6
            ,`read` = 0';
        DB\dbQuery($sql, $params) or die(DB\dbQueryError());
        $rez = DB\dbLastInsertId();
        return $rez;
    }
Exemplo n.º 2
0
 /**
  * add a record
  * @param  array $p associative array with table field values
  * @return int   created id
  */
 public static function create($p)
 {
     static::validateParamTypes($p);
     $cp = static::getCreateSqlParams($p);
     //prepare sql
     $sql = 'INSERT INTO ' . static::getTableName() . ' (`' . implode('`,`', $cp['fields']) . '`) VALUES (' . implode(',', $cp['params']) . ')';
     //add database record
     DB\dbQuery($sql, $cp['values']) or die(DB\dbQueryError());
     $rez = DB\dbLastInsertId();
     return $rez;
 }
Exemplo n.º 3
0
 /**
  * add a record
  * @param  array $p associative array with table field values
  * @return int   created id
  */
 public static function create($p)
 {
     parent::create($p);
     if (empty($p['name'])) {
         trigger_error(L\get('ErroneousInputData') . ' Empty name for GUID.', E_USER_ERROR);
     }
     //prepare params
     //add database record
     $sql = 'INSERT INTO ' . \CB\PREFIX . '_casebox.guids
             (`name`)
             VALUES ($1)';
     DB\dbQuery($sql, $p['name']) or die(DB\dbQueryError());
     $rez = DB\dbLastInsertId();
     return $rez;
 }
Exemplo n.º 4
0
 /**
  * add a record
  * @param  array $p associative array with table field values
  * @return int   created id
  */
 public static function create($p)
 {
     parent::create($p);
     //prepare params
     $params = array(empty($p['object_id']) ? null : $p['object_id'], empty($p['object_pid']) ? null : $p['object_pid'], empty($p['user_id']) ? null : $p['user_id'], empty($p['action_type']) ? null : $p['action_type'], empty($p['data']) ? null : $p['data'], empty($p['data']) ? null : $p['data'], empty($p['activity_data_db']) ? null : $p['activity_data_db'], empty($p['activity_data_solr']) ? null : $p['activity_data_solr']);
     //add database record
     $sql = 'INSERT INTO `' . static::$tableName . '` (
           `object_id`
           ,`object_pid`
           ,`user_id`
           ,`action_type`
           ,`data`
           ,`activity_data_db`
           ,`activity_data_solr`
         ) VALUES ($1, $2, $3, $4, $5, $6, $7)';
     DB\dbQuery($sql, $params) or die(DB\dbQueryError());
     $rez = DB\dbLastInsertId();
     return $rez;
 }
Exemplo n.º 5
0
 /**
  * add a record
  * @param  array $p associative array with table field values
  * @return int   created id
  */
 public static function create($p)
 {
     parent::create($p);
     $p = array_intersect_key($p, static::$tableFields);
     $p['type'] = static::$type;
     $fields = array_keys($p);
     $values = array_values($p);
     //prepare params
     $params = array_keys($values);
     $params[] = sizeof($params);
     array_shift($params);
     for ($i = 0; $i < sizeof($fields); $i++) {
         $params[$i] = $fields[$i] == 'password' ? 'MD5(CONCAT(\'aero\', $' . $params[$i] . '))' : '$' . $params[$i];
     }
     //prepare sql
     $sql = 'INSERT INTO `' . static::$tableName . '` (`' . implode('`,`', $fields) . '`) VALUES (' . implode(',', $params) . ')';
     //add database record
     DB\dbQuery($sql, $values) or die(DB\dbQueryError());
     $rez = DB\dbLastInsertId();
     return $rez;
 }
Exemplo n.º 6
0
 /**
  * copy an object to $pid or over $targetId
  *
  * better way to copy an object over another one is to delete the target,
  * but this could be very dangerous. We could delete required/important data
  * so i suggest to just mark overwriten object with dstatus = 3.
  * But in this situation appears another problem with child nodes.
  * Childs should be moved to new parent.
  *
  * @param  int $pid      if not specified then will be set to pid of targetId
  * @param  int $targetId
  * @return int the id of copied object
  */
 public function copyTo($pid = false, $targetId = false)
 {
     // check input params
     if (!is_numeric($this->id) || !is_numeric($pid) && !is_numeric($targetId)) {
         return false;
     }
     /* security check */
     if (!\CB\Security::canRead($this->id)) {
         return false;
     }
     /* end of security check */
     if (is_numeric($targetId)) {
         /* target security check */
         if (!\CB\Security::canWrite($targetId)) {
             return false;
         }
         /* end of target security check */
         // marking overwriten object with dstatus = 3
         DB\dbQuery('UPDATE tree
             SET  updated = 1
                 ,dstatus = 3
                 ,did = $2
             WHERE id = $1', array($targetId, $_SESSION['user']['id'])) or die(DB\dbQueryError());
         //get pid from target if not specified
         $res = DB\dbQuery('SELECT pid FROM tree WHERE id = $1', $targetId) or die(DB\dbQueryError());
         if ($r = $res->fetch_assoc()) {
             $pid = $r['pid'];
         }
         $res->close();
     } else {
         /* pid security check */
         if (!\CB\Security::canWrite($pid)) {
             return false;
         }
         /* end of pid security check */
     }
     /* check again if we have pid set
            It can be unset when not existent $targetId is specified
        */
     if (!is_numeric($pid)) {
         return false;
     }
     // copying the object to $pid
     DB\dbQuery('INSERT INTO `tree`
             (`id`
             ,`pid`
             ,`user_id`
             ,`system`
             ,`type`
             ,`template_id`
             ,`tag_id`
             ,`target_id`
             ,`name`
             ,`date`
             ,`date_end`
             ,`size`
             ,`is_main`
             ,`cfg`
             ,`inherit_acl`
             ,`cid`
             ,`cdate`
             ,`uid`
             ,`udate`
             ,`updated`
             ,`oid`
             ,`did`
             ,`ddate`
             ,`dstatus`)
         SELECT
             NULL
             ,$2
             ,`user_id`
             ,`system`
             ,`type`
             ,`template_id`
             ,`tag_id`
             ,`target_id`
             ,`name`
             ,`date`
             ,`date_end`
             ,`size`
             ,`is_main`
             ,`cfg`
             ,`inherit_acl`
             ,`cid`
             ,`cdate`
             ,$3
             ,CURRENT_TIMESTAMP
             ,1
             ,`oid`
             ,`did`
             ,`ddate`
             ,`dstatus`
         FROM `tree` t
         WHERE id = $1', array($this->id, $pid, $_SESSION['user']['id'])) or die(DB\dbQueryError());
     $objectId = DB\dbLastInsertId();
     /* we have now object created, so we start copy all its possible data:
            - tree_info is filled automaticly by trigger
            - custom security rules from tree_acl
            - custom object data
        */
     // copy node custom security rules if set
     \CB\Security::copyNodeAcl($this->id, $objectId);
     $this->copyCustomDataTo($objectId);
     // move childs from overwriten targetId (which has been marked with dstatus = 3)
     // to newly copied object
     if (is_numeric($targetId)) {
         DB\dbQuery('UPDATE tree
             SET updated = 1
                 ,pid = $2
             WHERE pid = $1 AND
                 dstatus = 0', array($targetId, $this->id)) or die(DB\dbQueryError());
     }
     return $objectId;
 }
Exemplo n.º 7
0
 /**
  * copy a source record under given $pid
  * @param  array $sourceId
  * @param  array $pid
  * @return int   created record id
  */
 public static function copy($sourceId, $pid)
 {
     DB\dbQuery('INSERT INTO `tree`
             (`id`
             ,`pid`
             ,`user_id`
             ,`system`
             ,`type`
             ,`template_id`
             ,`tag_id`
             ,`target_id`
             ,`name`
             ,`date`
             ,`date_end`
             ,`size`
             ,`is_main`
             ,`cfg`
             ,`inherit_acl`
             ,`cid`
             ,`cdate`
             ,`uid`
             ,`udate`
             ,`updated`
             ,`oid`
             ,`did`
             ,`ddate`
             ,`dstatus`)
         SELECT
             NULL
             ,$2
             ,`user_id`
             ,`system`
             ,`type`
             ,`template_id`
             ,`tag_id`
             ,`target_id`
             ,`name`
             ,`date`
             ,`date_end`
             ,`size`
             ,`is_main`
             ,`cfg`
             ,`inherit_acl`
             ,`cid`
             ,`cdate`
             ,$3
             ,CURRENT_TIMESTAMP
             ,1
             ,`oid`
             ,`did`
             ,`ddate`
             ,`dstatus`
         FROM `tree` t
         WHERE id = $1', array($sourceId, $pid, User::getId()));
     return DB\dbLastInsertId();
 }
Exemplo n.º 8
0
 /**
  * save fields property from this->data
  * @return void
  */
 protected function saveFields()
 {
     if (empty($this->data['fields'])) {
         return;
     }
     $tableFields = array('id', 'pid', 'name', 'l1', 'l2', 'l3', 'l4', 'type', 'order', 'cfg', 'solr_column_name');
     $keepFieldIds = array();
     foreach ($this->data['fields'] as $field) {
         $saveFields = array('template_id');
         $saveValues = array($this->id);
         $insertParams = array('$1');
         $updateParams = array();
         $i = 2;
         foreach ($tableFields as $fieldName) {
             $value = null;
             if (isset($field[$fieldName])) {
                 $value = is_scalar($field[$fieldName]) || is_null($field[$fieldName]) ? $field[$fieldName] : Util\jsonEncode($field[$fieldName]);
                 $saveFields[] = $fieldName;
                 $saveValues[] = $value;
                 $insertParams[] = "\${$i}";
                 if ($fieldName !== 'name') {
                     $updateParams[] = "`{$fieldName}` = \${$i}";
                 }
                 $i++;
             }
         }
         if (!empty($saveFields)) {
             DB\dbQuery('INSERT INTO templates_structure
                     (`' . implode('`,`', $saveFields) . '`)
                 VALUES (' . implode(',', $insertParams) . ')
                 ON DUPLICATE KEY UPDATE
                     ' . implode(',', $updateParams), $saveValues) or die(DB\dbQueryError());
             $keepFieldIds[] = DB\dbLastInsertId();
         }
     }
 }