示例#1
0
 private static function installFolders(Module_PM $module)
 {
     $folders = new GWF_PMFolder(false);
     if ($folders->countRows() === 0) {
         $folder = GWF_PMFolder::fakeFolder(0, 'INBOX');
         if (false === $folder->insert()) {
             return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
         $folder = GWF_PMFolder::fakeFolder(0, 'OUTBOX');
         if (false === $folder->insert()) {
             return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
     }
     return '';
 }
示例#2
0
 public function onDeleteFolder($folderid)
 {
     # Permission
     $folderid = (int) $folderid;
     $user = GWF_Session::getUser();
     if (false === ($folder = GWF_PMFolder::getByID($folderid)) || $folder->getVar('pmf_uid') !== $user->getID()) {
         return $this->module->error('err_folder_perm');
     }
     # Delete PMs$result
     $count = 0;
     $pms = GDO::table('GWF_PM');
     $uid = $user->getVar('user_id');
     $fid = "{$folderid}";
     $del = GWF_PM::OWNER_DELETED;
     if (false === ($result = $pms->update("pm_options=pm_options|{$del}", "pm_owner={$uid} AND pm_folder={$fid}"))) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     $count += $pms->affectedRows($result);
     //		$del = GWF_PM::FROM_DELETED;
     //		if (false === $pms->update("pm_options=pm_options|$del", "pm_from=$uid AND pm_from_folder=$fid")) {
     //			return GWF_HTML::err('ERR_DATABASE', array( __FILE__, __LINE__));
     //		}
     //		$count += $pms->affectedRows();
     if ($folderid > 2) {
         # Delete Folder
         if (false === $folder->delete()) {
             return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
     }
     # Done
     return $this->module->message('msg_folder_deleted', array($folder->display('pmf_name'), $count));
 }
示例#3
0
文件: Options.php 项目: sinfocol/gwf3
 /**
  * Put all your PMs into auto-folders.
  * @return string
  */
 private function onAutoFolder()
 {
     $user = GWF_Session::getUser();
     $userid = GWF_Session::getUserID();
     if (false === ($pmo = GWF_PMOptions::getPMOptions($user))) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     if (0 >= ($peak = $pmo->getAutoFolderValue())) {
         return $this->module->message('msg_auto_folder_off');
     }
     $del = GWF_PM::OWNER_DELETED;
     # count pm from and to user.
     $conditions = "(pm_owner={$userid} AND pm_options&{$del}=0)";
     $db = gdo_db();
     $pms = GDO::table('GWF_PM');
     $sorted = array();
     if (false === ($result = $pms->select('*', $conditions))) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     # Sort By UID
     while (false !== ($row = $db->fetchAssoc($result))) {
         $pm = new GWF_PM($row);
         $other_user = $pm->getOtherUser($user);
         $other_uid = $other_user->getID();
         if (!isset($sorted[$other_uid])) {
             $sorted[$other_uid] = array();
         }
         $sorted[$other_uid][] = $pm;
     }
     $db->free($result);
     $back = '';
     foreach ($sorted as $uid => $pms) {
         if (count($pms) < $peak) {
             continue;
         }
         $other_user = $pms[0]->getOtherUser($user);
         $foldername = $other_user->getVar('user_name');
         # Create the folder if not exists.
         if (false === ($folder = GWF_PMFolder::getByName($foldername, $user))) {
             $folder = GWF_PMFolder::fakeFolder($user->getID(), $foldername);
             if (false === $folder->insert()) {
                 return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
             }
             $back .= $this->module->message('msg_auto_folder_created', array($other_user->displayUsername()));
         }
         $moved = 0;
         foreach ($pms as $pm) {
             if (false !== $pm->move($user, $folder)) {
                 $moved++;
             }
         }
         if ($moved > 0) {
             $back .= $this->module->message('msg_auto_folder_moved', array($moved, $other_user->displayUsername()));
         }
     }
     return $back . $this->module->message('msg_auto_folder_done');
 }
示例#4
0
 public static function getFolders($userid, $orderby = 'pmf_name ASC')
 {
     return array_merge(GWF_PMFolder::getDefaultFolders(), GDO::table('GWF_PMFolder')->selectObjects('*', 'pmf_uid=' . intval($userid), $orderby));
 }
示例#5
0
 public function validate_foldername($arg)
 {
     $_POST['foldername'] = $arg = trim($arg);
     if (false !== GWF_PMFolder::getByName($arg)) {
         return $this->lang('err_folder_exists');
     }
     $len = GWF_String::strlen($arg);
     $max = $this->cfgMaxFolderNameLen();
     if ($len < 1 || $len > $max) {
         return $this->lang('err_folder_len', $max);
     }
     return false;
 }
示例#6
0
文件: GWF_PM.php 项目: sinfocol/gwf3
 public function move(GWF_User $user, GWF_PMFolder $folder)
 {
     if (false === ($old_folder = $this->getFolder($user))) {
         return false;
     }
     if ($old_folder->getID() === $folder->getID()) {
         return false;
     }
     if (false === $this->saveVar('pm_folder', $folder->getID())) {
         return false;
     }
     if (false === $folder->increase('pmf_count', 1)) {
         return false;
     }
     if (false === $old_folder->increase('pmf_count', -1)) {
         return false;
     }
     $this->markRead($user, true);
     return true;
 }
示例#7
0
 private function onMove($ids = NULL)
 {
     $ids = Common::getPost('pm');
     if (!is_array($ids)) {
         return '';
     }
     $user = GWF_Session::getUser();
     if (false === ($folder = GWF_PMFolder::getByID(Common::getPost('folders')))) {
         return $this->module->error('err_folder');
     }
     if ($folder->getVar('pmf_uid') !== $user->getID()) {
         return $this->module->error('err_folder');
     }
     $count = 0;
     foreach ($ids as $id => $stub) {
         if (false === ($pm = GWF_PM::getByID($id))) {
             continue;
         }
         if (false === $pm->canRead($user)) {
             continue;
         }
         if (false === $pm->move($user, $folder)) {
             continue;
         }
         $count++;
     }
     $this->sanitize();
     return $this->module->message('msg_moved', array($count));
 }