コード例 #1
0
 static function cutcopy_items($folder, $view, $items, $operation)
 {
     if (!is_array($items)) {
         return array();
     }
     $writeable = $operation == "cut";
     $sgsml = new sgsml($folder, $view, $items, $writeable);
     if (!isset($sgsml->buttons[$operation])) {
         return array();
     }
     $tname = $sgsml->tname;
     $rows = $sgsml->get_rows(array("id"));
     if (is_array($rows) and count($rows) == 0 and count($items) == 0) {
         return array();
     }
     if (!is_array($rows) or count($rows) == 0 or count($rows) < count($items)) {
         exit("{t}Item(s) not found or access denied.{/t}");
     }
     $items = array();
     foreach ($rows as $row) {
         $items[] = $row["id"];
     }
     $unique_fields = array();
     $file_fields = array();
     $data_fields = array();
     foreach ($sgsml->fields as $field) {
         if (isset($field["DISABLE_CCP"])) {
             continue;
         }
         if (isset($field["KEY"]) or isset($field["IS_UNIQUE"])) {
             $unique_fields[] = $field["NAME"];
         }
         if ($field["SIMPLE_TYPE"] == "files") {
             $file_fields[] = $field["NAME"];
         }
         $data_fields[] = $field["NAME"];
     }
     $delete_mode = isset($sgsml->buttons["delete"]) ? "delete" : "purge";
     return array("operation" => $operation, "tname" => $tname, "custom_name" => $sgsml->att["CUSTOM_NAME"], "default_sql" => $sgsml->current_view["DEFAULT_SQL"], "handler" => $sgsml->handler, "items" => $items, "folder" => $folder, "folders" => $sgsml->vars["folders"], "unique_fields" => $unique_fields, "file_fields" => $file_fields, "delete_mode" => $delete_mode, "data_fields" => $data_fields, "where" => $sgsml->where, "vars_noquote" => $sgsml->vars_noquote);
 }
コード例 #2
0
ファイル: asset.php プロジェクト: drognisep/Simple-Groupware
 static function delete_items($folder, $view, $items, $mode = "delete")
 {
     if (empty($folder) or empty($view) or !is_array($items) or $mode == "") {
         return;
     }
     $sgsml = new sgsml($folder, $view, $items);
     $tname = $sgsml->tname;
     $handler = $sgsml->handler;
     if (!isset($sgsml->buttons[$mode]) or $mode == "delete" and count($items) == 0) {
         return;
     }
     if ($mode == "empty") {
         $sgsml->where = array("folder in (@folders@)");
     }
     if ($mode == "purgeall") {
         $sgsml->where = array();
     }
     if (in_array($mode, array("purge", "purgeall"))) {
         $delete = true;
     } else {
         $delete = false;
     }
     if (folder_in_trash($folder)) {
         $delete = true;
     }
     if ($handler == "") {
         $file_fields = $sgsml->get_fields_by_type("files");
     } else {
         $file_fields = array();
     }
     if (!empty($sgsml->att["TRIGGER_DELETE"])) {
         $fields = array("*");
     } else {
         if (isset($sgsml->fields["notification"])) {
             $fields = array("id", "folder", "notification");
             foreach ($sgsml->fields as $key => $field) {
                 if (isset($field["REQUIRED"]) and $field["SIMPLE_TYPE"] != "files" and !in_array($key, $fields)) {
                     $fields[] = $key;
                 }
             }
         } else {
             $fields = array("id");
         }
         $fields = array_unique(array_merge($fields, $file_fields));
     }
     $rows = $sgsml->get_rows($fields);
     if (!is_array($rows) or count($rows) == 0 or count($rows) < count($items)) {
         exit("{t}Item(s) not found or access denied.{/t}");
     }
     if ($delete) {
         foreach ($rows as $row) {
             foreach ($file_fields as $field) {
                 $files = explode("|", $row[$field]);
                 sys_unlink($files);
             }
             $data = array("id" => $row["id"], "folder" => $folder);
             db_delete($tname, array("id=@id@"), $data, array("handler" => $handler));
         }
     } else {
         $trash = db_select_value("simple_sys_tree", "id", "anchor=@anchor@", array("anchor" => "trash"));
         if (empty($trash)) {
             exit("{t}Error{/t}: {t}Trash folder not found.{/t}");
         }
         foreach ($rows as $row) {
             $id = folders::create(sys_date("{t}m/d/Y{/t}"), "blank", "", $trash, true);
             $tid = folders::create($sgsml->att["MODULENAME"], str_replace("simple_", "", $tname), "", $id, true);
             $data = array("folder" => $tid, "history" => sprintf("{t}Item deleted by %s at %s{/t}\n", $_SESSION["username"], sys_date("{t}m/d/y g:i:s a{/t}")));
             db_update($tname, $data, array("id=@id@"), array("id" => $row["id"]), array("handler" => $handler));
             db_update_treesize($tname, $tid);
             if (!isset($row["notification"])) {
                 $row["notification"] = "";
             }
             $tree_notification = db_select_value("simple_sys_tree", "notification", "id=@id@", array("id" => $folder));
             if ($tree_notification) {
                 $row["notification"] .= "," . $tree_notification;
             }
             if (!empty($row["notification"])) {
                 $smtp_data = self::build_notification($tname, $sgsml->fields, $row, $data, $id);
                 asset_process_trigger("sendmail", $row["id"], $smtp_data);
             }
             if (!empty($sgsml->att["TRIGGER_DELETE"])) {
                 asset_process_trigger($sgsml->att["TRIGGER_DELETE"], $row["id"], $row, $tname);
             }
             db_update("simple_sys_tree", array("history" => "[" . $row["id"] . "/details] " . $data["history"]), array("id=@id@"), array("id" => $folder));
             db_search_delete($tname, $row["id"], $folder);
             db_notification_delete($tname, $row["id"]);
         }
     }
     db_update_treesize($tname, $folder);
     sys_log_stat("deleted_records", count($rows));
 }
コード例 #3
0
ファイル: ajax.php プロジェクト: drognisep/Simple-Groupware
 static function file_download($folder, $view, $id, $field, $subitem, $write)
 {
     self::_require_access($folder, "read", $view);
     $sgsml = new sgsml($folder, $view, (array) $id, $write);
     $data = $sgsml->get_rows(array("id", "folder", sql_fieldname($field)));
     if (empty($data[0][$field])) {
         exit("{t}Item(s) not found or access denied.{/t}");
     }
     $files = explode("|", trim($data[0][$field], "|"));
     if (!is_numeric($subitem) and $subitem != "") {
         foreach ($files as $key => $file) {
             if (modify::basename($file) == $subitem) {
                 $subitem = $key;
                 break;
             }
         }
     }
     if (!is_numeric($subitem)) {
         $subitem = 0;
     }
     if (empty($files[$subitem])) {
         exit("{t}file not found in database.{/t}");
     }
     $file = sys_remove_handler($files[$subitem]);
     if (!file_exists($file)) {
         exit("{t}file not found.{/t}");
     }
     return $file;
 }