getId(); $ret = $tdb->query("SELECT * FROM ".DB_PREFIX."_folders WHERE userID=".$userID." AND folderID=".$_SESSION['folderid']); $finfo = mysql_fetch_array($ret); $this->folderinfo = $finfo; } } function getTasks() { $tks = get_tasks(); $tks [] = array('typeIdent'=>'image', 'title'=>'Image', 'icon'=>'plugins/image/image.gif'); return $tks; } public function getShow() { if (isset($_GET['show'])) { return $_GET['show']; } else { return "all"; } } public function getPageType() { if (isset($_GET['pid'])) { return $_GET['pid']; } return "Folder"; } public function getFID() { if (isset($_GET['fid'])) { return $_GET['fid']; } else { return false; } } /* public function editContent() { global $tops, $tdb; $title = "Modify folder"; $extf = $_GET['fid']; $ret = $tdb->query("SELECT * FROM ".DB_PREFIX."_folders WHERE folderId=".$extf); $f = mysql_fetch_array($ret); $fti = $f['title']; //$tops->out("popup", sprintf($this->folder_templ, $title, $fti, $extf)); } */ /** * @Secured('roles' = {'authenticated'}, 'valid' = {}) * */ public function actionFolderHandler() { global $tdb, $user; if ( strlen(trim($_POST['extfid'])) > 0 ) { // modify existing $_SESSION['folderid'] = $_POST['extfid']; $q = "UPDATE ".DB_PREFIX."_folders set title='%s' WHERE folderId=%s"; $q = sprintf($q, $_POST['ftitle'], $_POST['extfid']); $tdb->query($q); } else { // create new if ( $_SESSION['folderid'] != NULL ) { $q = "INSERT INTO ".DB_PREFIX."_folders (parentFolder, userId, title) values (%s, %s, '%s')"; $q = sprintf($q, $_SESSION['folderid'], $user->getId(), $_POST['ftitle']); } else { $q = "INSERT INTO ".DB_PREFIX."_folders (userId, title) values (%s, '%s')"; $q = sprintf($q, $user->getId(), $_POST['ftitle']); } $tdb->query($q); $autoid = mysql_insert_id(); $_SESSION['folderid'] = $autoid; } return array('pid' => 'Folder'); } public function validate_ownership() { global $user, $tdb; if ( $user->hasRole('manager') ) { return 0; } if ( !isset($_GET['fid']) || !is_numeric($_GET['fid']) ) { return 1; } $q = "SELECT * FROM ".DB_PREFIX."_folders WHERE folderId=".$_GET['fid']; $ret = $tdb->query($q); $f = mysql_fetch_array($ret); if ( $f['userId'] != $user->getId() ) { return 1; } return 0; } public function getCurrentFolderTitle() { return $this->folderinfo['title']; } public function getLinkUp() { if ( $this->folderinfo['parentFolder'] == NULL ) { return "?pid=MyFolder"; } return "?pid=Folder&fid=".$this->folderinfo['parentFolder']; } function multi_sort(&$array, $key, $asc=true) { $sorter = new array_sorter($array, $key, $asc); return $sorter->sortit(); } public function getTableContents() { $conts = array(); foreach ($this->getFolders() as $folder) { $conts []= array('title'=>$folder['title'],'created'=>'','type'=>gettext('Folder'),'url'=>'?pid=Folder&fid='.$folder['folderID'],'delt'=>'folders','rid'=>$folder['folderID'], 'obj'=>NULL, 'dtype'=>'folder','icon'=>'plugins/folder/folder.gif'); } foreach ($this->getResources() as $reso) { $conts []= array('title'=>$reso->getTitle(),'created'=>$reso->getCreated(),'type'=>gettext(ucfirst($reso->getType())),'url'=>'?rid='.$reso->getResourceId().'&mode=view','delt'=>'tasks','rid'=>$reso->getResourceId(), 'obj'=>$reso, 'dtype'=>'resource','icon'=>getTypeIcon($reso->getType(), $reso->getResourceId())); } if ($this->getPageType()=="MyFolder") { foreach ($this->getAnswerObjects() as $answer) { $url = "?rid=".$answer['resourceID']."&aid=".$answer['answerID']."&mode=answer"; $resob = $answer['resob']; $conts []= array('title'=>$resob['title'],'created'=>$answer['created'],'type'=>gettext(ucfirst($resob['type']).' answer') ,'url'=>$url,'delt'=>'answers','rid'=>$answer['answerID'], 'obj'=>NULL, 'dtype'=>'answer','icon'=>getTypeIcon($resob['type'], $answer['resourceID'])); } } if ( isset($_GET['sort'])) { $order = true; if ( isset($_GET['order']) && $_GET['order']=="desc") { $order = false; } $conts = $this->multi_sort($conts, $_GET['sort'], $order); } return $conts; } public function getFolders() { global $tdb, $user; if ( $_SESSION['folderid'] != NULL ) { $withparent = "AND parentFolder=".$_SESSION['folderid']; } else { $withparent = "AND parentFolder IS NULL"; } $ret = $tdb->query(sprintf("SELECT * FROM ".DB_PREFIX."_folders WHERE userId=%s %s", $user->getId(), $withparent)); $res = array(); while ( $row = mysql_fetch_array($ret) ) { $res[] = $row; } return $res; } function isinhome() { if ( $_SESSION['folderid'] == NULL ) { return 1; } return 0; } function getResources() { global $tops, $tdb, $user; $fi = isset($_SESSION['folderid']) ? "=".$_SESSION['folderid'] : " IS NULL"; $userID = $user->getId(); $reso = $tdb->getResourcesByType("all", array('userID'=>$userID." AND folderid".$fi)); /*$reso = array(); while ( $row = mysql_fetch_array($ret) ) { $td = get_type_desc($row['type']); if ( $td == NULL ) { continue; } array_push($reso, $row); }*/ return $reso; } /** * @Secured('roles' = {'authenticated'}, 'valid' = {}) * */ public function actionDelete(){ global $tdb; $message = "No objects selected for delete!"; $notices = array(); $cfolders = 0; if (isset($_POST['folders'])){ $fids = $_POST['folders']; $errors = array(); foreach ($fids as $fid){ $ftitle = ""; $ret1 = $tdb->query("SELECT title FROM ".DB_PREFIX."_folders WHERE folderID=".$fid); while ( $row = mysql_fetch_array($ret1) ) { $ftitle = $row['title']; } $ret = $tdb->query("SELECT title FROM ".DB_PREFIX."_folders WHERE parentFolder=".$fid); if (mysql_num_rows($ret)>0) { $errors []= sprintf(gettext("Folder '%s' has %s subfolders"), $ftitle, mysql_num_rows($ret)); } else { $ret = $tdb->query("SELECT resourceID FROM ".DB_PREFIX."_resources WHERE folderid=".$fid); if (mysql_num_rows($ret)>0) { $errors []= sprintf(gettext("Folder '%s' has %s objects"), $ftitle, mysql_num_rows($ret)); } else { $res = $tdb->query("DELETE FROM ".DB_PREFIX."_folders WHERE folderID=".$fid); if ($res) { $cfolders++; } } } } if ($cfolders>0) { $nm = sprintf(gettext('%s folders has been deleted'), $cfolders); if (count($errors)>0) { $nm .= " ".gettext(", but with errors").": ".join($errors, ", "); } $notices []= $nm; } else { $notices []= gettext("No folders deleted, because").": ".join($errors, ", "); } } if (isset($_POST['tasks'])){ $ctasks = 0; foreach ($_POST['tasks'] as $rid){ $games_used = 0; $images_used = mysql_num_rows($tdb->query("SELECT ".DB_PREFIX."_usedimages.resourceID FROM ".DB_PREFIX."_usedimages LEFT JOIN ".DB_PREFIX."_images ON ".DB_PREFIX."_images.imageUID = ".DB_PREFIX."_usedimages.imageUID WHERE ".DB_PREFIX."_images.resourceID=".$rid)); $del_act = false; if ( $games_used>0 || $images_used>0 ){ $del_act = $tdb->query("UPDATE ".DB_PREFIX."_resources SET deleted=1 WHERE resourceID=".$rid); } else { $del_act = $tdb->query("DELETE FROM ".DB_PREFIX."_resources WHERE resourceID=".$rid); } if ($del_act) { $ctasks++; } } if ($ctasks>0) { if ($ctasks>1) { $notices []= sprintf(gettext('%s objects has been deleted'), $ctasks); } else { $notices []= gettext('1 object has been deleted'); } } } if (isset($_POST['fid']) && is_numeric($_POST['fid']) && $_POST['fid']>0) { return array('pid' => 'Folder', 'fid' => $_POST['fid']); } if (count($notices)>0){ $_SESSION['tops_notice'] = join($notices, ", "); } else { $_SESSION['tops_notice'] = gettext($message); } return array('pid' => 'MyFolder'); } /** * @Secured(roles={'authenticated'}) * */ function actionCancel() { $_SESSION['tops_notice'] = gettext("Action cancelled!"); if (isset($_SESSION['folderid']) && $_SESSION['folderid']!="NULL") { return array('pid' => 'Folder', 'fid' => $_SESSION['folderid']); } return array('pid' => 'MyFolder'); } } ?>