improved folder feature

This commit is contained in:
SJ 2015-09-18 14:56:09 +02:00
parent 9769694821
commit 04a0f2b6ef
12 changed files with 138 additions and 68 deletions

View File

@ -19,7 +19,7 @@ class ControllerFolderList extends Controller {
$this->document->title = $this->data['text_folders'];
if(isset($this->request->post['name']) && $this->request->post['name']) {
$this->model_folder_folder->add_extra_folder($this->request->post['name']);
$this->model_folder_folder->add_folder($this->request->post['name']);
Header("Location: folders.php");
return;
@ -27,7 +27,7 @@ class ControllerFolderList extends Controller {
if(isset($this->request->get['id']) && $this->request->get['id'] > 0) {
$this->model_folder_folder->remove_extra_folder($this->request->get['id']);
$this->model_folder_folder->remove_folder($this->request->get['id']);
Header("Location: folders.php");
return;
@ -36,7 +36,7 @@ class ControllerFolderList extends Controller {
$this->data['page_len'] = get_page_length();
$this->data['extra_folders'] = $this->model_folder_folder->get_extra_folders_for_user();
$this->data['extra_folders'] = $this->model_folder_folder->get_folders_for_user();
$this->render();
}

View File

@ -0,0 +1,31 @@
<?php
class ControllerMessageFolder extends Controller {
private $error = array();
public function index(){
$this->id = "content";
$this->template = "message/note.tpl";
$this->layout = "common/layout-empty";
$session = Registry::get('session');
$request = Registry::get('request');
$db = Registry::get('db');
$sphx = Registry::get('sphx');
$this->load->model('search/search');
$this->load->model('folder/folder');
if(isset($this->request->post['folder_id']) && isset($this->request->post['id'])) {
if($this->model_search_search->check_your_permission_by_id($this->request->post['id']) == 1) {
$this->model_folder_folder->update_message_folder($this->request->post['id'], $this->request->post['folder_id']);
}
}
}
}
?>

View File

@ -19,6 +19,10 @@ class ControllerMessageView extends Controller {
$this->load->model('user/user');
if(ENABLE_FOLDER_RESTRICTIONS == 1) {
$this->load->model('folder/folder');
}
$this->document->title = $this->data['text_message'];
$this->data['id'] = '';
@ -83,6 +87,11 @@ class ControllerMessageView extends Controller {
$this->data['can_download'] = $this->model_audit_audit->can_download();
$this->data['can_restore'] = $this->model_audit_audit->can_restore();
if(ENABLE_FOLDER_RESTRICTIONS == 1) {
$this->data['folders'] = $this->model_folder_folder->get_folders_for_user();
$this->data['folder_id'] = $this->model_folder_folder->get_folder_id_by_id($this->data['id']);
}
foreach($this->data['attachments'] as $a) {
if(preg_match("/image/", $a['type'])) {
$attachment = $this->model_search_message->get_attachment_by_id($a['id']);

View File

@ -14,8 +14,8 @@ class ControllerSearchFolder extends Controller {
$this->load->model('folder/folder');
$this->data['folders'] = $this->model_folder_folder->get_folders_for_user();
$this->data['extra_folders'] = $this->model_folder_folder->get_extra_folders_for_user();
$this->data['extra_folders'] = $this->model_folder_folder->get_folders_for_user();
array_unshift($this->data['extra_folders'], array('id' => 0, 'name' => '---'));
$this->data['folders_by_hier'] = $this->model_folder_folder->get_all_folder_ids_hier($session->get("uid"));

View File

@ -61,7 +61,11 @@ class ModelFolderFolder extends Model {
$q = str_repeat("?,", count($session->get("folders")));
$q = preg_replace("/\,$/", "", $q);
if(isAuditorUser() == 1) {
$query = $this->db->query("SELECT `id`, `name` FROM `" . TABLE_FOLDER);
} else {
$query = $this->db->query("SELECT `id`, `name` FROM `" . TABLE_FOLDER . "` WHERE id IN ($q)", $session->get("folders"));
}
if(isset($query->rows)) { return $query->rows; }
@ -69,21 +73,12 @@ class ModelFolderFolder extends Model {
}
public function get_extra_folders_for_user() {
private function is_your_folder($folder_id = 0) {
$session = Registry::get('session');
$query = $this->db->query("SELECT `id`, `name` FROM `" . TABLE_FOLDER_EXTRA . "` WHERE uid=? ORDER BY name", array($session->get("uid")));
if(isAuditorUser() == 1) { return 1; }
if(isset($query->rows)) { return $query->rows; }
return array();
}
private function is_your_extra_folder($folder_id = 0) {
$session = Registry::get('session');
$query = $this->db->query("SELECT `id` FROM `" . TABLE_FOLDER_EXTRA . "` WHERE uid=? AND id=?", array($session->get("uid"), $folder_id));
$query = $this->db->query("SELECT f.id AS id FROM `" . TABLE_FOLDER . "` f, " . TABLE_FOLDER_USER . "` fu WHERE f.id=fu.id AND fu.uid=? AND f.id=?", array($session->get("uid"), $folder_id));
if(isset($query->row['id'])) { return 1; }
return 0;
@ -91,17 +86,21 @@ class ModelFolderFolder extends Model {
public function copy_message_to_folder_by_id($folder_id = 0, $meta_id = 0) {
if(!$this->is_your_extra_folder($folder_id)) { return -1; }
if(!$this->is_your_folder($folder_id)) { return -1; }
$query = $this->db->query("INSERT INTO " . TABLE_FOLDER_MESSAGE . " (folder_id, id) VALUES(?,?)", array($folder_id, $meta_id));
return $this->db->countAffected();
}
public function get_all_folder_ids($uid = 0) {
public function get_folder_id_array_for_user($uid = 0, $is_admin = 0) {
$arr = array();
if($is_admin == 2) {
$query = $this->db->query("SELECT id FROM `" . TABLE_FOLDER);
} else {
$query = $this->db->query("SELECT id FROM `" . TABLE_FOLDER_USER . "` WHERE uid=?", array($uid));
}
if(isset($query->rows)) {
foreach ($query->rows as $q) {
@ -132,21 +131,6 @@ class ModelFolderFolder extends Model {
}
public function get_all_extra_folder_ids($uid = 0) {
$arr = array();
$query = $this->db->query("SELECT id FROM `" . TABLE_FOLDER_EXTRA . "` WHERE uid=?", array($uid));
if(isset($query->rows)) {
foreach ($query->rows as $q) {
array_push($arr, $q['id']);
}
}
return $arr;
}
private function get_sub_folders($id = 0, &$arr = array()) {
$query = $this->db->query("SELECT id FROM `" . TABLE_FOLDER . "` WHERE parent_id=?", array($id));
@ -203,32 +187,55 @@ class ModelFolderFolder extends Model {
}
public function add_extra_folder($name = '') {
public function get_folder_id_by_id($id = 0) {
$query = $this->db->query("SELECT folder_id FROM `" . TABLE_FOLDER_MESSAGE . "` WHERE id=?", array($id));
if(isset($query->row)) { return $query->row['folder_id']; }
return 0;
}
public function update_message_folder($id = 0, $folder_id = 0) {
$query = $this->db->query("UPDATE `" . TABLE_FOLDER_MESSAGE . "` SET folder_id=? WHERE id=?", array($folder_id, $id));
//$query = $this->sphx->query("UPDATE " . SPHINX_MAIN_INDEX . " SET folder=? WHERE id=?", array($folder_id, $id));
$query = $this->sphx->query("UPDATE " . SPHINX_MAIN_INDEX . " SET folder=$folder_id WHERE id=$id");
}
public function add_folder($name = '') {
if($name == '') { return -1; }
$session = Registry::get('session');
$query = $this->db->query("INSERT INTO " . TABLE_FOLDER_EXTRA . " (uid, name) VALUES(?,?)", array($session->get("uid"), $name));
$query = $this->db->query("INSERT INTO " . TABLE_FOLDER . " (name) VALUES(?)", array($name));
if(isAuditorUser() == 0) {
$last_id = $this->db->getLastId();
$query = $this->db->query("INSERT INTO " . TABLE_FOLDER_USER . " (id, uid) VALUES(?,?)", array($last_id, $session->get("uid")));
$extra_folders = $session->get("extra_folders");
if(!isset($extra_folders[$last_id])) { array_push($extra_folders, $last_id); }
$folders = $session->get("folders");
if(!isset($folders[$last_id])) { array_push($folders, $last_id); $session->set("folders", $folders); }
}
return $this->db->countAffected();
}
public function remove_extra_folder($id = 0) {
if($id == 0) { return -1; }
public function remove_folder($id = 0) {
if($id <= 0) { return -1; }
$session = Registry::get('session');
$query = $this->db->query("DELETE FROM " . TABLE_FOLDER_EXTRA . " WHERE id=? AND uid=?", array($id, $session->get("uid")));
if($this->db->countAffected() == 1) {
$query = $this->db->query("DELETE FROM " . TABLE_FOLDER_MESSAGE . " WHERE folder_id=?", array($id));
return $this->db->countAffected();
if($this->is_your_folder($id) == 1) {
$query = $this->db->query("DELETE FROM " . TABLE_FOLDER . " WHERE id=?", array($id));
$query = $this->db->query("DELETE FROM " . TABLE_FOLDER_USER . " WHERE id=? AND uid=?", array($id, $session->get("uid")));
$folders = $session->get("folders");
if(isset($folders[$id])) { unset($folders[$id]); $session->set("folders", $folders); }
// shall we delete the existing message - folder id assignments from folder_message?
}
return 0;

View File

@ -223,9 +223,10 @@ class ModelSearchSearch extends Model {
list ($total_found, $num_rows, $id_list) = $this->get_sphinx_id_list($data['note'], SPHINX_NOTE_INDEX, 'note', $page);
$query = $this->sphx->query("SELECT id FROM " . SPHINX_MAIN_INDEX . " WHERE $folders id IN ($id_list) $sortorder LIMIT 0,$pagelen OPTION max_matches=" . MAX_SEARCH_HITS);
}
else if(ENABLE_FOLDER_RESTRICTIONS == 1 && isset($data['extra_folders']) && $data['extra_folders']) {
list ($total_found, $num_rows, $ids_in_extra_folders) = $this->get_sphinx_id_list_by_extra_folders($data['extra_folders'], $page);
$query = $this->sphx->query("SELECT id FROM " . SPHINX_MAIN_INDEX . " WHERE $a $id $date $attachment $direction $size MATCH('$match') AND id IN ($ids_in_extra_folders) $sortorder LIMIT 0,$pagelen OPTION max_matches=" . MAX_SEARCH_HITS);
else if(ENABLE_FOLDER_RESTRICTIONS == 1 && isset($data['extra_folders']) && strlen($data['extra_folders']) > 0) {
$query = $this->sphx->query("SELECT id FROM " . SPHINX_MAIN_INDEX . " WHERE $a $id $date $attachment $direction $size folder IN (" . preg_replace("/ /", ",", $data['extra_folders']) . ") AND MATCH('$match') $sortorder LIMIT $offset,$pagelen OPTION max_matches=" . MAX_SEARCH_HITS);
$total_found = $query->total_found;
$num_rows = $query->num_rows;
}
else {
$query = $this->sphx->query("SELECT id FROM " . SPHINX_MAIN_INDEX . " WHERE $a $id $date $attachment $direction $size $folders MATCH('$match') $sortorder LIMIT $offset,$pagelen OPTION max_matches=" . MAX_SEARCH_HITS);

View File

@ -16,7 +16,6 @@ class ModelUserAuth extends Model {
$session->set("emails", $data['emails']);
$session->set("folders", $data['folders']);
$session->set("extra_folders", $data['extra_folders']);
}
@ -35,7 +34,6 @@ class ModelUserAuth extends Model {
$data['auditdomains'] = array();
$data['emails'] = array();
$data['folders'] = array();
$data['extra_folders'] = array();
if($username == '' || $password == '') { return 0; }
@ -114,8 +112,7 @@ class ModelUserAuth extends Model {
$extra_emails = $this->model_user_user->get_email_addresses_from_groups($data['emails']);
$data['emails'] = array_merge($data['emails'], $extra_emails);
$data['folders'] = $this->model_folder_folder->get_all_folder_ids($query->row['uid']);
$data['extra_folders'] = $this->model_folder_folder->get_all_extra_folder_ids($query->row['uid']);
$data['folders'] = $this->model_folder_folder->get_folder_id_array_for_user($query->row['uid'], $data['admin_user']);
$session->set("auth_data", $data);
@ -323,7 +320,6 @@ class ModelUserAuth extends Model {
$data['auditdomains'] = $this->model_domain_domain->get_your_all_domains_by_email($email);
$data['emails'] = $emails;
$data['folders'] = array();
$data['extra_folders'] = array();
$uid = $this->model_user_user->get_uid_by_email($email);
if($uid < 1) {

View File

@ -41,8 +41,7 @@ class ModelUserGoogle extends Model {
$session->set("realname", $query->row['realname']);
$session->set("emails", $this->model_user_user->get_users_all_email_addresses($user['uid']));
$session->set("folders", $this->model_folder_folder->get_all_folder_ids($user['uid']));
$session->set("extra_folders", $this->model_folder_folder->get_all_extra_folder_ids($user['uid']));
$session->set("folders", $this->model_folder_folder->get_folder_id_array_for_user($user['uid']));
AUDIT(ACTION_LOGIN, $user['username'], '', '', 'successful auth against Google');

View File

@ -425,6 +425,23 @@ var Piler =
},
update_message_folder:function(id, msg)
{
Piler.log("[update_message_folder]", id, msg);
Piler.poor_mans_keepalive_for_dummy_browsers();
jQuery.ajax('index.php?route=message/folder', {
data: { id: id, folder_id: $('#folder_id').val() },
type: "POST"
})
.done( function(a) {})
.fail(function(a, b) { alert("Problem retrieving XML data:" + b) });
Piler.show_message('messagebox1', msg, 0.85);
},
tag_search_results:function(msg)
{
Piler.log("[tag_search_results]", msg);

View File

@ -1658,6 +1658,7 @@ html,body{height:auto !important;height:100%;min-height:100%;}
#popupx{position:absolute;right:10px;top:5px;margin:10px;cursor:pointer;}
#restorebox{position:absolute;top:40px;left:15%;display:none;font-weight:bold;padding:15px;z-index:1;}
#notesbox{position:absolute;top:8px;right:8px;}
#folderbox{position:absolute;top:8px;right:380px;}
#sspinner{display:none;}
.message_highlight{background:lightblue;}
#searchcontainer{text-align:center;min-width:320px;}
@ -1669,7 +1670,7 @@ html,body{height:auto !important;height:100%;min-height:100%;}
#searchcontainer #button_search,#searchcontainer #button_options{width:30%;}
#mainscreen{position:absolute;top:120px;right:20px;bottom:20px;left:20px;min-width:320px;z-index:0;}
#mailleftcontainer{position:absolute;top:0;left:0;bottom:0;width:195px;}
#mailboxlist-container{position:absolute;top:0;left:0;width:100%;bottom:0;border:1px solid #999999;border-top:none;background-color:#f9f9f9;overflow:hidden;}
#mailboxlist-container{position:absolute;top:0;left:0;width:100%;bottom:0;border:1px solid #999999;border-top:none;background-color:#f9f9f9;overflow:auto;}
.boxlistcontent{position:absolute;top:0px;bottom:34px;left:0;right:0;width:100%;overflow-y:auto;overflow-x:hidden;height:auto;}
.boxfooter{position:absolute;bottom:0px;left:0px;right:0px;overflow:hidden;height:33px;border-top:1px solid #ccc;background-color:#f6f6f6;min-width:320px;}
#mailboxlist{position:relative;height:auto;margin:0px;padding:0px;list-style-image:none;list-style-type:none;overflow:hidden;white-space:nowrap;background-color:#FFF;}
@ -1730,4 +1731,6 @@ body#loginpage{background-color:#fcfcfc;padding-top:40px;padding-bottom:40px;}
.control-group.success .fileupload .fileupload-preview{color:#468847;}
.control-group.success .fileupload .thumbnail{border-color:#468847;}
.bottomborder { border-bottom: 1px solid black; }
.folderlabel{display: block; padding-left: 35px; text-indent: -15px;}
.foldercheckbox{vertical-align: center; position: relative; top: -1px; margin:0; padding: 0; height: 13px; width: 13px;}
@media (min-width:980px){body{padding-top:65px;}}@media (max-width:980px){.navbar-fixed-top{margin-bottom:10px;} .nav-collapse .nav>li>a,.nav-collapse .dropdown-menu a{font-weight:normal;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0;} .nav-collapse .nav>li>a:hover,.nav-collapse ul.nav li.dropdown ul.dropdown-menu li a:hover{color:#fff;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0;background-color:#555555;} .navbar .nav li.dropdown>a:hover .caret{border-top-color:#fff;border-bottom-color:#fff;} .dropdown-menu li>a:hover{background-color:#00f;}}@media (max-width:767px){#mainscreen{top:162px;} #pagingrow{border-bottom:1px solid #ccc;} #pagingbox{border-right:none;} #functionbox{border-left:none;} .boxlistcontent{bottom:68px;overflow:scroll;} .boxfooter{height:67px;}}

View File

@ -43,6 +43,18 @@
<input type="button" class="btn btn-info" value="<?php print $text_save; ?>" class="message_button" onclick="Piler.add_note_to_message(<?php print $id; ?>, '<?php print $text_saved; ?>'); " />
</div>
<?php if(ENABLE_FOLDER_RESTRICTIONS == 1) { ?>
<div id="folderbox" class="input-prepend input-append">
<span class="add-on"><i class="icon-folder-open-alt icon-large"></i>&nbsp;<?php print $text_folder; ?>:</span>
<select name="folder_id" id="folder_id" class="span2">
<option value="0" <?php if($folder_id == 0) { ?>selected="selected"<?php } ?>>---</option>
<?php foreach ($folders as $folder) { ?>
<option value="<?php print $folder['id']; ?>" <?php if($folder_id == $folder['id']) { ?>selected="selected"<?php } ?>><?php print $folder['name']; ?></option>
<?php } ?>
</select>
<input type="button" class="btn btn-info" value="<?php print $text_save; ?>" class="message_button" onclick="Piler.update_message_folder(<?php print $id; ?>, '<?php print $text_saved; ?>'); " />
</div>
<?php } ?>
<div id="messageblock">

View File

@ -2,17 +2,12 @@
<div id="folders">
<?php foreach ($extra_folders as $folder) { ?>
<blockquote class="folder">
<form class="form-search sleek">
<img src="<?php print ICON_EMPTY; ?>" width="12" height="12" alt="" /> <input type="checkbox" id="extra_folder_<?php print $folder['id']; ?>" name="extra_folder_<?php print $folder['id']; ?>" /> <input type="text" ondrop="Piler.copy_message_to_folder('<?php print $folder['id']; ?>', Piler.current_message_id, '<?php print $text_copied; ?>'); return false;" class="input-small bold" style="color: #850505; border:none; background: transparent; " value="<?php print $folder['name']; ?>" />
</form>
</blockquote>
<div>
<label class="folderlabel"><input type="checkbox" id="extra_folder_<?php print $folder['id']; ?>" name="extra_folder_<?php print $folder['id']; ?>" style="margin:0;" class="foldercheckbox" /> <?php print $folder['name']; ?></label>
</div>
<?php } ?>
<?php
function display_folders($arr = array(), &$i) {
@ -43,7 +38,7 @@ function display_folders($arr = array(), &$i) {
<?php
$i = 0;
display_folders($folders_by_hier, $i);
//display_folders($folders_by_hier, $i);
?>