Exemple #1
0
 public function __construct()
 {
     mgActivateThisPlugin(__FILE__, array(__CLASS__, 'activate'));
     //Инициализация  метода выполняющегося при активации
     mgAddAction(__FILE__, array(__CLASS__, 'pageSettingsPlugin'));
     //Инициализация  метода выполняющегося при нажатии на кнопку настроект плагина
     mgAddShortcode('trigger-guarantee', array(__CLASS__, 'viewTrigger'));
     // Инициализация шорткода [trigger-guarantee] - доступен в любом HTML коде движка.
     self::$pluginName = PM::getFolderPlugin(__FILE__);
     self::$lang = PM::plugLocales(self::$pluginName);
     self::$path = PLUGIN_DIR . self::$pluginName;
     mgAddMeta('<link rel="stylesheet" href="' . SITE . '/' . self::$path . '/css/style.css" type="text/css" />');
 }
Exemple #2
0
 public function trigger_action($id)
 {
     if (!character::selected()) {
         return api::result(false, array('message' => 'No_character_selected'));
     }
     $trigger = trigger::load_one((int) $id);
     if (!$trigger) {
         return api::result(false, array('message' => 'Trigger_not_found'));
     }
     $char = character::current();
     if ($trigger->map_id !== $char->map_id) {
         return api::result(false, array('message' => 'Trigger_out_of_range'));
     }
     return $trigger->run_script();
 }
 public static function import_createedit($tfolder, $module, $username, $lastsync, $fields)
 {
     $table_source = "fnbl_simple_" . $module . "_imp";
     $table_dest = "simple_" . $module;
     $sys_date = date("Y-m-d H:i:s");
     $db_date = sgsml_parser::sql_date();
     if (abs(strtotime($sys_date) - strtotime($db_date)) > 60) {
         sys_warning("{t}Error{/t}: {t}current time{/t} {t}System{/t}: " . $sys_date . " {t}Database{/t}: " . $db_date);
     }
     if (DEBUG) {
         echo "Sync4j: " . $table_source . " lastmodified > " . $lastsync . " " . date("c", $lastsync);
     }
     $count_insert = 0;
     $count_update = 0;
     $rows = db_select($table_source, "*", array("userid=@username@", "lastmodified > @lastmodified@"), "", "", array("username" => $username, "lastmodified" => $lastsync - 600));
     if (is_array($rows) and count($rows) > 0) {
         foreach ($rows as $row) {
             if ($row["status"] == "D") {
                 // delete
                 self::_import_delete($tfolder, $row["syncid"], $table_dest, $module);
                 continue;
             }
             unset($row["userid"]);
             unset($row["status"]);
             if ($table_dest == "simple_contacts" and empty($row["contactid"])) {
                 continue;
             }
             if ($table_dest == "simple_tasks") {
                 if (empty($row["begin"]) and empty($row["ending"])) {
                     continue;
                 }
                 if (empty($row["begin"])) {
                     $row["begin"] = $row["ending"];
                 }
             }
             $exists = db_select_value($table_dest, "id", "syncid=@id@", array("id" => $row["syncid"]));
             if (!empty($exists)) {
                 $id = $exists;
             } else {
                 $id = 0;
             }
             if ($id != 0) {
                 // update
                 $row["history"] = sprintf("{t}Item edited (%s) by %s at %s{/t} (sync)\n", "@fields@", $_SESSION["username"], sys_date("{t}m/d/y g:i:s a{/t}"));
                 $cdata = "";
                 $data = $row;
                 $cfields = array();
                 $data_old = db_select_first($table_dest, "*", "id=@id@", "", array("id" => $id));
                 if (!empty($data_old["id"])) {
                     if ($row["lastmodified"] == $data_old["lastmodified"]) {
                         continue;
                     }
                     foreach ($data as $key => $val) {
                         if (isset($data_old[$key]) and $key != "history") {
                             if ($data_old[$key] != $val) {
                                 if (trim($val) != "") {
                                     $cdata .= $key . ": " . $val . "\n";
                                 }
                                 $cfields[] = $key;
                             } else {
                                 unset($data[$key]);
                             }
                         }
                     }
                 }
                 if (count($data) < 3) {
                     continue;
                 }
                 $data["history"] = str_replace("@fields@", implode(", ", $cfields), $data["history"]) . $cdata . "\n";
                 if (DEBUG) {
                     print_r($data);
                 }
                 $error_sql = db_update($table_dest, $data, array("id=@id@"), array("id" => $id));
                 $count_update++;
             } else {
                 // new
                 $id = sql_genID($table_dest) * 100;
                 $row["id"] = $id;
                 $row["folder"] = $tfolder;
                 $row["dsize"] = 0;
                 $row["history"] = sprintf("{t}Item created by %s at %s{/t} (sync)\n", $_SESSION["username"], sys_date("{t}m/d/y g:i:s a{/t}"));
                 if (DEBUG) {
                     print_r($row);
                 }
                 $error_sql = db_insert($table_dest, $row);
                 $count_insert++;
             }
             if ($error_sql == "") {
                 if ($module == "calendar") {
                     trigger::calcappointment($id, $row, false, "simple_calendar");
                 }
                 if ($module == "tasks") {
                     trigger::duration($id, $row, false, "simple_tasks");
                 }
                 trigger::notify($id, $row, array(), "simple_" . $module);
                 db_search_update($table_dest, $id, $fields);
                 if ($count_insert > 0) {
                     sys_log_stat("new_records", $count_insert);
                 }
                 if ($count_update > 0) {
                     sys_log_stat("changed_records", $count_update);
                 }
             }
         }
     }
     db_update_treesize($table_dest, $tfolder);
     return "";
 }
Exemple #4
0
function install()
{
    setup::out('
    <html>
    <head>
	<title>Simple Groupware & CMS</title>
	<style>
	  body { width:526px; margin:10px auto; }
	  body, a { color: #666666; font-size: 13px; font-family: Arial, Helvetica, Verdana, sans-serif; }
	  a { color: #0000FF; }
	</style>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
    <body>
	<div style="border-bottom: 1px solid #666666; letter-spacing: 2px; font-size: 18px; font-weight: bold;">Simple Groupware ' . CORE_VERSION_STRING . '</div>
  ');
    $_SESSION["groups"] = array();
    $_SESSION["username"] = "******";
    $_SESSION["password"] = "";
    $_SESSION["permission_sql"] = "1=1";
    $_SESSION["permission_sql_read"] = "1=1";
    $_SESSION["permission_sql_write"] = "1=1";
    define("SETUP_DB_TYPE", $_REQUEST["db_type"]);
    $update = sgsml_parser::table_column_exists("simple_sys_tree", "id");
    setup::out('<img src="http://www.simple-groupware.de/cms/logo.php/' . CORE_VERSION . '/' . SETUP_DB_TYPE . '/' . PHP_VERSION . '/' . (int) $update . '" style="width:1px; height:1px;">', false);
    setup::out(t("{t}Processing %s ...{/t}", "schema updates"));
    setup_update::change_database_pre();
    if (SETUP_DB_TYPE == "sqlite") {
        sql_query("begin");
        admin::rebuild_schema(false);
        sql_query("commit");
    } else {
        admin::rebuild_schema(false);
    }
    setup_update::change_database_post();
    setup::out(t("{t}Processing %s ...{/t}", "sessions"));
    db_delete("simple_sys_session", array(), array());
    setup::out(t("{t}Processing %s ...{/t}", "default groups"));
    $groups = array("admin_calendar", "admin_news", "admin_projects", "admin_bookmarks", "admin_contacts", "admin_inventory", "admin_helpdesk", "admin_organisation", "admin_files", "admin_payroll", "admin_surveys", "admin_hr", "admin_intranet", "users_self_registration");
    foreach ($groups as $group) {
        trigger::creategroup($group);
    }
    setup_update::database_triggers();
    setup::out(t("{t}Processing %s ...{/t}", "folder structure"));
    $count = db_select_value("simple_sys_tree", "id", array());
    if (empty($count)) {
        $folders = "modules/core/folders.xml";
        if (!empty($_REQUEST["folders"]) and file_exists(sys_custom($_REQUEST["folders"]))) {
            $folders = $_REQUEST["folders"];
        }
        if (SETUP_DB_TYPE == "sqlite") {
            sql_query("begin");
            folders::create_default_folders($folders, 0, true);
            sql_query("commit");
        } else {
            folders::create_default_folders($folders, 0, true);
        }
    }
    setup_update::database_folders();
    setup::out(t("{t}Processing %s ...{/t}", "css"));
    admin::build_css();
    setup::out(t("{t}Processing %s ...{/t}", "js"));
    admin::build_js();
    setup::out(t("{t}Processing %s ...{/t}", "icons"));
    admin::build_icons();
    setup::out(t("{t}Processing %s ...{/t}", "config.php"));
    $vars = array("SETUP_DB_TYPE" => "'" . $_REQUEST["db_type"] . "'", "SETUP_DB_HOST" => "'" . $_REQUEST["db_host"] . "'", "SETUP_DB_NAME" => "'" . $_REQUEST["db_name"] . "'", "SETUP_DB_USER" => "'" . $_REQUEST["db_user"] . "'", "SETUP_DB_PW" => "'" . sys_encrypt($_REQUEST["db_pw"], sha1($_REQUEST["admin_user"])) . "'", "SETUP_ADMIN_USER" => "'" . $_REQUEST["admin_user"] . "'", "SETUP_ADMIN_PW" => "'" . (isset($_REQUEST["auto_update"]) ? $_REQUEST["admin_pw"] : sha1($_REQUEST["admin_pw"])) . "'");
    setup::save_config($vars);
    setup::install_footer();
    db_optimize_tables();
}
Exemple #5
0
 static function process_logout()
 {
     trigger::logout();
     if (!sys_is_guest($_SESSION["username"])) {
         sys_log_message_log("login", sprintf("{t}logout %s{/t}", $_SESSION["username"]));
     }
     session_destroy();
 }
Exemple #6
0
 public function triggers()
 {
     static $triggers = null;
     if (!$triggers) {
         $triggers = trigger::load($this->id, 'map_id')->fetchAll();
     }
     return $triggers;
 }
Exemple #7
0
 $smtp_data = array("efrom" => "", "eto" => $notification["eto"], "subject" => $notification["subject"], "message" => trim($notification["message"]), "attachment" => $notification["attachment"], "folder" => "cron");
 $result = asset_process_trigger("sendmail", "", $smtp_data);
 if ($result != "") {
     echo "ERROR " . $notification["eto"] . ": " . $result . "\n";
     sys_log_message_log("php-fail", $result, var_export($smtp_data, true));
     db_update("simple_sys_notifications", array("error" => $result), array("id=@id@"), array("id" => $notification["id"]));
 } else {
     $data = array("error" => "");
     if (!empty($notification["recurrence"])) {
         if ($notification["recurrence"][0] == "|") {
             $match = array();
             preg_match("/([^\\|]+)\\|([^&]+)/", $notification["reference"], $match);
             if (!empty($match) and count($match) == 3) {
                 $row = db_select_first($match[1], "*", "id=@id@", "", array("id" => $match[2]));
                 if (!empty($row)) {
                     trigger::notify($match[2], $row, array(), $match[1]);
                 }
             }
         } else {
             $counter = 0;
             $data["delivery"] = $notification["delivery"];
             while ($data["delivery"] < NOW and $counter < 150) {
                 $data["delivery"] = strtotime($notification["recurrence"], $data["delivery"]);
                 $counter++;
             }
         }
     } else {
         $data["sent"] = "1";
     }
     db_update("simple_sys_notifications", $data, array("id=@id@"), array("id" => $notification["id"]));
     $log .= "ID: " . $notification["id"] . "\n";
 private static function _parse($file)
 {
     if ($data = sys_cache_get("icalendar_" . sha1($file))) {
         return $data;
     }
     if ($message = sys_allowedpath(dirname($file))) {
         sys_warning(sprintf("{t}Cannot read the file %s. %s{/t}", $file, $message));
         return array();
     }
     $rows = array();
     if (!($handle = fopen($file, "rb"))) {
         sys_warning(sprintf("{t}Cannot read the file %s. %s{/t}", $file, ""));
         return array();
     }
     $i = 0;
     $evopen = false;
     $lines = array();
     while (!feof($handle)) {
         $line = fgets($handle, 10000);
         $line = str_replace(array("\r", "\n", "\\n"), array("", "", "\n"), $line);
         if ($line == "") {
             continue;
         }
         if ($line[0] == " ") {
             $lines[count($lines) - 1] .= substr($line, 1);
         } else {
             $lines[] = $line;
         }
     }
     fclose($handle);
     foreach ($lines as $line) {
         $line = trim($line);
         switch ($line) {
             case "BEGIN:VEVENT":
                 $i++;
                 $evopen = true;
                 $rows[$i] = array("subject" => "", "begin" => 0, "ending" => 0, "created" => 0, "duration" => 0, "lastmodified" => 0, "allday" => "0", "location" => "", "description" => "", "organizer" => array(), "participants_ext" => array(), "category" => "", "priority" => "3", "recurrence" => "", "repeatinterval" => 1, "repeatcount" => "0", "repeatuntil" => 0, "repeatexcludes" => array());
                 break;
             case "BEGIN:VALARM":
                 $evopen = false;
                 break;
             case "END:VEVENT":
                 $evopen = false;
                 $begin = sys_getdate($rows[$i]["begin"]);
                 $end = sys_getdate($rows[$i]["ending"]);
                 if ($rows[$i]["lastmodified"] == 0) {
                     $rows[$i]["lastmodified"] = $rows[$i]["created"];
                 }
                 if ($begin["hours"] == 0 and $end["hours"] == 0 and $begin["minutes"] == 0 and $end["minutes"] == 0) {
                     if ($rows[$i]["begin"] == $rows[$i]["ending"]) {
                         $rows[$i]["ending"] += 86399;
                     } else {
                         $rows[$i]["ending"]--;
                     }
                     $rows[$i]["allday"] = "1";
                 }
                 foreach ($rows[$i] as $key => $item) {
                     if (is_array($item)) {
                         $rows[$i][$key] = self::_array_flat($item);
                     }
                 }
                 if ($rows[$i]["ending"] != "" and $rows[$i]["begin"] != "") {
                     $rows[$i]["duration"] = $rows[$i]["ending"] - $rows[$i]["begin"];
                 }
                 $rows[$i] = array_merge($rows[$i], trigger::calcappointment("", $rows[$i], null, ""));
                 // $rows[$i]["begin_str"] = date("D d-m-y H:i:s",$rows[$i]["begin"]);
                 // $rows[$i]["end_str"] = date("D d-m-y H:i:s",$rows[$i]["ending"]);
                 break;
             default:
                 if (!$evopen) {
                     break;
                 }
                 $pos = strpos($line, ":");
                 $first = substr($line, 0, $pos);
                 $value_str = str_replace(array("\\,", "\\n", "\\N"), array(",", "\n", "\n"), substr($line, $pos + 1));
                 if ($pos2 = strpos($first, ";")) {
                     $kval = substr($first, 0, $pos2);
                 } else {
                     $kval = $first;
                 }
                 switch ($kval) {
                     case "SUMMARY":
                         $rows[$i]["subject"] = $value_str;
                         break;
                     case "DESCRIPTION":
                         $rows[$i]["description"] = $value_str;
                         break;
                     case "LOCATION":
                         $rows[$i]["location"] = $value_str;
                         break;
                     case "CLASS":
                         if ($rows[$i]["category"] != "" and $value_str != "") {
                             $rows[$i]["category"] .= ",";
                         }
                         $rows[$i]["category"] .= ucfirst(strtolower($value_str));
                         break;
                     case "CATEGORIES":
                         if ($rows[$i]["category"] != "") {
                             $rows[$i]["category"] .= ",";
                         }
                         $rows[$i]["category"] .= $value_str;
                         break;
                     case "UID":
                         $rows[$i]["id"] = $value_str;
                         break;
                     case "SEQUENCE":
                         $rows[$i]["sequence"] = $value_str;
                         break;
                     case "DTSTART":
                         $rows[$i]["begin"] = modify::ical_datetime_to_int($value_str);
                         break;
                     case "DTEND":
                         $rows[$i]["ending"] = modify::ical_datetime_to_int($value_str);
                         break;
                     case "LAST-MODIFIED":
                         $rows[$i]["lastmodified"] = modify::ical_datetime_to_int($value_str);
                         break;
                     case "DTSTAMP":
                         $rows[$i]["created"] = modify::ical_datetime_to_int($value_str);
                         break;
                     case "DURATION":
                         if (!preg_match("/PT?([0-9]{1,2}W)?([0-9]{1,2}D)?([0-9]{1,2}H)?([0-9]{1,2}M)?/", $value_str, $match)) {
                             break;
                         }
                         $match = array_merge($match, array(0, 0, 0, 0));
                         $rows[$i]["ending"] = $rows[$i]["begin"] + str_replace("W", "", $match[1]) * 604800 + str_replace("D", "", $match[2]) * 86400 + str_replace("H", "", $match[3]) * 3600 + str_replace("M", "", $match[4]) * 60;
                         break;
                     case "RRULE":
                         $value = explode(";", $value_str);
                         foreach ($value as $val) {
                             $val = explode("=", $val);
                             switch ($val[0]) {
                                 case "FREQ":
                                     switch ($val[1]) {
                                         case "YEARLY":
                                             $rows[$i]["recurrence"] = "years";
                                             break;
                                         case "MONTHLY":
                                             $rows[$i]["recurrence"] = "months";
                                             break;
                                         case "WEEKLY":
                                             $rows[$i]["recurrence"] = "weeks";
                                             break;
                                         case "DAILY":
                                             $rows[$i]["recurrence"] = "days";
                                             break;
                                     }
                                     break;
                                 case "INTERVAL":
                                     $rows[$i]["repeatinterval"] = $val[1];
                                     break;
                                 case "COUNT":
                                     $rows[$i]["repeatcount"] = $val[1];
                                     break;
                                 case "UNTIL":
                                     $rows[$i]["repeatuntil"] = modify::ical_datetime_to_int($val[1]);
                                     break;
                             }
                         }
                         break;
                     case "EXDATE":
                         $rows[$i]["repeatexcludes"][] = modify::ical_datetime_to_int($value_str);
                         break;
                     case "ORGANIZER":
                         $value = explode(";", $value_str);
                         $key = explode(";", $first);
                         if (isset($value[1])) {
                             $value[0] = $value[1];
                         }
                         if (isset($key[1])) {
                             $value[0] = str_replace(array("CN=", "\""), "", $key[1]) . " (" . str_replace(array("MAILTO:", "mailto:"), "", $value[0]) . ")";
                         }
                         $rows[$i]["organizer"][] = $value[0];
                         break;
                     case "ATTENDEE":
                         $value = explode(";", $value_str);
                         $key = explode(";", $first);
                         if (isset($value[1])) {
                             $value[0] = $value[1];
                         }
                         $value[0] = str_replace(array("MAILTO:", "mailto:"), "", $value[0]);
                         if (isset($key[1]) and strpos($key[1], "CN=") !== false) {
                             $value[0] = str_replace(array("CN=", "\""), "", $key[1]) . " (" . $value[0] . ")";
                         }
                         $rows[$i]["participants_ext"][] = $value[0];
                         break;
                     default:
                         // echo $line."<br>\n";
                         break;
                 }
                 break;
         }
     }
     sys_cache_set("icalendar_" . sha1($file), $rows, ICALENDAR_CACHE);
     return $rows;
 }
 static function database_triggers()
 {
     // 0.664
     if (!file_exists(SIMPLE_STORE . "/setup_emails")) {
         setup::out(sprintf("{t}Processing %s ...{/t}", "emails message"));
         $rows = db_select("simple_emails", "*", array("message_html='' and message!=''"), "", "");
         if (is_array($rows) and count($rows) > 0) {
             foreach ($rows as $row) {
                 trigger::createemail($row["id"], $row);
             }
         }
         touch(SIMPLE_STORE . "/setup_emails");
     }
     // 0.704
     if (!file_exists(SIMPLE_STORE . "/setup_notify")) {
         $notifications = array("simple_tasks" => "closed='0'", "simple_contacts" => "birthday!=''", "simple_contactactivities" => "finished='0'", "simple_sys_users" => "activated='1'");
         foreach ($notifications as $table => $where) {
             setup::out(sprintf("{t}Processing %s ...{/t}", $table));
             $rows = db_select($table, "*", array($where, "notification!=''"), "", "");
             if (!is_array($rows) or count($rows) == 0) {
                 continue;
             }
             foreach ($rows as $row) {
                 trigger::notify($row["id"], $row, array(), $table);
             }
         }
         touch(SIMPLE_STORE . "/setup_notify");
     }
     if (!file_exists(SIMPLE_STORE . "/setup_duration")) {
         setup::out(sprintf("{t}Processing %s ...{/t}", "tasks duration"));
         $rows = db_select("simple_tasks", "*", array(), "", "");
         if (is_array($rows) and count($rows) > 0) {
             foreach ($rows as $row) {
                 trigger::duration($row["id"], $row, false, "simple_tasks");
             }
         }
         setup::out(sprintf("{t}Processing %s ...{/t}", "projects duration"));
         $rows = db_select("simple_projects", "*", array(), "", "");
         if (is_array($rows) and count($rows) > 0) {
             foreach ($rows as $row) {
                 trigger::createeditproject($row["id"], $row);
             }
         }
         touch(SIMPLE_STORE . "/setup_duration");
     }
     setup::out(sprintf("{t}Processing %s ...{/t}", "appointments"));
     $rows = db_select("simple_calendar", "*", array(), "", "");
     if (is_array($rows) and count($rows) > 0) {
         foreach ($rows as $row) {
             trigger::calcappointment($row["id"], $row, null, "simple_calendar");
         }
     }
 }