Exemplo n.º 1
0
 public function createFolder($path)
 {
     $pid = explode('/', $path);
     $pid = array_pop($pid);
     if (!is_numeric($pid)) {
         return array('success' => false);
     }
     /* check security access */
     if (!Security::canCreateFolders($pid)) {
         throw new \Exception(L\get('Access_denied'));
     }
     /* find default folder name */
     $newFolderName = L\get('NewFolder');
     $existing_names = array();
     $res = DB\dbQuery('SELECT name
         FROM tree
         WHERE pid = $1
             AND name LIKE $2', array($pid, $newFolderName . '%')) or die(DB\dbQueryError());
     while ($r = $res->fetch_assoc()) {
         $existing_names[] = $r['name'];
     }
     $res->close();
     $i = 1;
     while (in_array($newFolderName, $existing_names)) {
         $newFolderName = L\get('NewFolder') . ' (' . $i . ')';
         $i++;
     }
     /* end of find default folder name */
     DB\dbQuery('INSERT INTO tree
             (pid
             ,user_id
             ,`type`
             ,`name`
             ,cid
             ,uid
             ,template_id)
         VALUES ($1
             ,$2
             ,$3
             ,$4
             ,$2
             ,$2
             ,$3)', array($pid, $_SESSION['user']['id'], 1, $newFolderName, Config::get('default_folder_template'))) or die(DB\dbQueryError());
     $id = DB\dbLastInsertId();
     Solr\Client::runCron();
     return array('success' => true, 'path' => $path, 'data' => array('nid' => $id, 'pid' => $pid, 'name' => $newFolderName, 'system' => 0, 'type' => 1, 'iconCls' => 'icon-folder', 'cid' => $_SESSION['user']['id']));
 }