Example #1
0
 static function notify($id, $data, $params, $table)
 {
     db_notification_delete($table, $id);
     if (empty($data["notification"]) or folder_in_trash($data["folder"])) {
         return "";
     }
     if (class_exists("notify") and method_exists("notify", $table)) {
         return call_user_func(array("notify", $table), $id, $data, $params, $table);
     }
     return "";
 }
Example #2
0
 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));
 }