Example #1
0
 /**
  * merge files
  * To be reviewed
  *
  * @param  int  $ids
  * @return json response
  */
 public function merge($ids)
 {
     if (!is_array($ids)) {
         return array('success' => false);
     }
     $ids = Util\toNumericArray($ids);
     if (sizeof($ids) < 2) {
         return array('success' => false);
     }
     $to_id = null;
     $res = DB\dbQuery('SELECT id
         FROM tree
         WHERE id IN (' . implode(', ', $ids) . ')
         ORDER BY udate DESC, id DESC');
     if ($r = $res->fetch_assoc()) {
         $to_id = $r['id'];
     }
     $res->close();
     DB\dbQuery('UPDATE files_versions
         SET file_id = $1
         WHERE file_id IN (' . implode(', ', $ids) . ')', $to_id);
     $res = DB\dbQuery('INSERT INTO files_versions (file_id, content_id, `date`, name, cid, uid, cdate, udate)
             SELECT $1
                 ,content_id
                 ,`date`
                 ,name
                 ,cid
                 ,uid
                 ,cdate
                 ,udate
             FROM files
             WHERE id <> $1
                 AND id in(' . implode(',', $ids) . ')', $to_id);
     DB\dbQuery('UPDATE tree
         SET did = $2
                 , dstatus = 1
                 , updated = (updated | 1)
         WHERE id <> $1
             AND id IN (' . implode(', ', $ids) . ')', array($to_id, User::getId()));
     DM\Tree::update(array('id' => $to_id, 'updated' => 1));
     $ids = array_diff($ids, array($to_id));
     // Objects::updateCaseUpdateInfo($id);
     Solr\Client::runCron();
     return array('success' => true, 'rez' => $ids);
 }
Example #2
0
 /**
  * create shorcut(s)
  * @param  object $p input params
  * @return json   responce
  */
 public function shortcut($p)
 {
     if (!$this->validateParams($p)) {
         return array('success' => false, 'msg' => L\get('ErroneousInputData'));
     }
     /* security checks */
     foreach ($p['sourceIds'] as $sourceId) {
         if (!\CB\Security::canRead($sourceId)) {
             return array('success' => false, 'msg' => L\get('Access_denied'));
         }
     }
     if (!\CB\Security::canWrite($p['targetId'])) {
         return array('success' => false, 'msg' => L\get('Access_denied'));
     }
     $rez = array('success' => true, 'targetId' => $p['targetId'], 'processedIds' => array());
     $shortcutObject = new Objects\Shortcut();
     foreach ($p['sourceIds'] as $id) {
         $rez['processedIds'][] = $shortcutObject->create(array('id' => null, 'pid' => $p['targetId'], 'target_id' => $id));
     }
     Solr\Client::runCron();
     return $rez;
 }
Example #3
0
 /**
  * remove own comment
  * @param array $p input params (id)
  */
 public function removeComment($p)
 {
     $rez = array('success' => false);
     if (empty($p['id']) || !is_numeric($p['id'])) {
         $rez['msg'] = L\get('Wrong_input_data');
         return $rez;
     }
     $comment = static::getCustomClassByObjectId($p['id']);
     $commentData = $comment->load();
     if ($commentData['cid'] == $_SESSION['user']['id']) {
         $comment->delete();
         Solr\Client::runCron();
         $rez['success'] = true;
     }
     return $rez;
 }
Example #4
0
 public static function deleteObject($id)
 {
     $file = new \CB\Objects\Object($id);
     $file->delete();
     \CB\Solr\Client::runCron();
 }
Example #5
0
 public static function checkRootFolder()
 {
     $id = null;
     $res = DB\dbQuery('SELECT id
         FROM tree
         WHERE pid IS NULL
             AND `system` = 1
             AND `is_main` = 1') or die(DB\dbQueryError());
     if ($r = $res->fetch_assoc()) {
         $id = $r['id'];
     }
     $res->close();
     /* create root folder */
     if ($id == null) {
         DB\dbQuery('INSERT INTO tree
                 (`system`
                 , `name`
                 , is_main
                 , updated
                 , template_id)
             VALUES (1
                 ,\'root\'
                 ,1
                 ,1
                 ,$1)', Config::get('default_folder_template')) or die(DB\dbQueryError());
         $id = DB\dbLastInsertId();
         Solr\Client::runCron();
     }
     return $id;
 }
Example #6
0
 /**
  * get email folder id for specified user id. If folder does not exist it is created automaticly.
  * @param  int $user_id
  * @return int email folder id
  */
 public static function getEmailFolderId($user_id = false)
 {
     $rez = null;
     if (empty($user_id)) {
         $user_id = $_SESSION['user']['id'];
     }
     $pid = User::getUserHomeFolderId($user_id);
     $res = DB\dbQuery('SELECT id
         FROM tree
         WHERE user_id = $1
             AND SYSTEM = 1
             AND pid =$2
             AND type = 1', array($_SESSION['user']['id'], $pid)) or die(DB\dbQueryError());
     if ($r = $res->fetch_assoc()) {
         $rez = $r['id'];
     }
     $res->close();
     if (empty($rez)) {
         DB\dbQuery('INSERT INTO tree (
                 pid
                 ,user_id
                 ,`system`
                 ,`type`
                 ,`name`
                 ,cid
                 ,uid
                 ,template_id)
             VALUES (
                 $1
                 ,$2
                 ,1
                 ,1
                 ,\'[Emails]\'
                 ,$3
                 ,$3
                 ,$4)', array($pid, $user_id, $_SESSION['user']['id'], Config::get('default_folder_template'))) or die(DB\dbQueryError());
         $rez = DB\dbLastInsertId();
         Solr\Client::runCron();
     }
     return $rez;
 }
Example #7
0
 public function confirmUploadRequest($p)
 {
     //if cancel then delete all uploaded files from incomming
     $files = new Files();
     $a = $files->getUploadParams();
     $a['response'] = $p['response'];
     switch ($p['response']) {
         case 'rename':
             $a['newName'] = Purify::filename($p['newName']);
             //check if the new name does not also exist
             if (empty($a['response'])) {
                 return array('success' => false, 'msg' => L\get('FilenameCannotBeEmpty'));
             }
             reset($a['files']);
             $k = key($a['files']);
             $a['files'][$k]['name'] = $a['newName'];
             if ($files->fileExists($a['pid'], $a['newName'])) {
                 $files->saveUploadParams($a);
                 return array('success' => false, 'type' => 'filesexist', 'allow_new_version' => Files::getMFVC($a['newName']) > 0, 'suggestedFilename' => Objects::getAvailableName($a['pid'], $a['newName']), 'msg' => str_replace('{filename}', '"' . $a['newName'] . '"', L\get('FilenameExistsInTarget')));
             }
             // $files->storeFiles($a);
             // break;
         // $files->storeFiles($a);
         // break;
         case 'newversion':
         case 'replace':
         case 'autorename':
             $files->storeFiles($a);
             break;
         default:
             //cancel
             $files->removeIncomingFiles($a['files']);
             return array('success' => true, 'data' => array());
             break;
     }
     Solr\Client::runCron();
     $rez = array('success' => true, 'data' => array('pid' => $a['pid']));
     $files->attachPostUploadInfo($a['files'], $rez);
     return $rez;
 }