+// Subtract points from database and mediadata cache
+function SUB_POINTS ($uid, $points) {
+ // Add points to used points
+ $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET `used_points`=`used_points`+%s WHERE userid=%s LIMIT 1",
+ array($points, bigintval($uid)), __FILE__, __LINE__);
+
+ // Update mediadata as well
+ if (GET_EXT_VERSION("mediadata") >= "0.0.4") {
+ // Update database
+ MEDIA_UPDATE_ENTRY(array("total_points"), "sub", $points);
+ } // END - if
+}
+// Update config entries
+function UPDATE_CONFIG ($entries, $values, $updateMode="") {
+ // Do we have multiple entries?
+ if (is_array($entries)) {
+ // Walk through all
+ $all = "";
+ foreach ($entries as $idx => $entry) {
+ // Update mode set?
+ if (!empty($updateMode)) {
+ // Update entry
+ $all .= sprintf("%s=%s%s%s,", $entry, $entry, $updateMode, (float)$values[$idx]);
+ } else {
+ // Check if string or number
+ if (($values[$idx] + 0) === $values[$idx]) {
+ // Number detected
+ $all .= sprintf("%s=%s,", $entry, (float)$values[$idx]);
+ } else {
+ // String detected
+ $all .= sprintf("%s='%s',", $entry, SQL_ESCAPE($values[$idx]));
+ }
+ }
+ } // END - foreach
+
+ // Remove last comma
+ $entries = substr($all, 0, -1);
+ } elseif (!empty($updateMode)) {
+ // Update mode set
+ $entries .= sprintf("=%s%s%s", $entries, $updateMode, (float)$value);
+ } else {
+ // Regular entry to update
+ $entries .= sprintf("='%s'", SQL_ESCAPE($values));
+ }
+
+ // Run database update
+ //DEBUG_LOG(__FUNCTION__.":entries={$entries}");
+ SQL_QUERY("UPDATE "._MYSQL_PREFIX."_config SET ".$entries." WHERE config=0 LIMIT 1", __FILE__, __LINE__);
+
+ // Get affected rows
+ $affectedRows = SQL_AFFECTEDROWS();
+ //* DEBUG: */ echo __FUNCTION__.":entries={$entries},affectedRows={$affectedRows}<br />\n";
+
+ // Rebuild cache
+ REBUILD_CACHE("config", "config");
+}
+// Creates a new task for updated extension
+function CREATE_EXTENSION_UPDATE_TASK ($admin_id, $subject, $notes) {
+ // Check if task is not there
+ $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_task_system WHERE subject='%s' LIMIT 1",
+ array($subject), __FILE__, __LINE__);
+ if (SQL_NUMROWS($result) == 0) {
+ // Task not created so it's a brand-new extension which we need to register and create a task for!
+ $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_task_system (assigned_admin, userid, status, task_type, subject, text, task_created) VALUES ('%s','0','NEW','EXTENSION_UPDATE','%s','%s', UNIX_TIMESTAMP())",
+ array($admin_id, $subject, $notes), __FILE__, __LINE__);
+ } // END - if
+
+ // Free memory
+ SQL_FREERESULT($result);
+}
+// Creates a new task for newly installed extension
+function CREATE_NEW_EXTENSION_TASK ($admin_id, $subject, $ext) {
+ // Not installed and do we have created a task for the admin?
+ $result = SQL_QUERY_ESC("SELECT `id` FROM `"._MYSQL_PREFIX."_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1",
+ array($subject), __FILE__, __LINE__);
+ if ((SQL_NUMROWS($result) == 0) && (GET_EXT_VERSION($ext) == "")) {
+ // Template file
+ $tpl = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
+ PATH,
+ GET_LANGUAGE(),
+ $ext
+ );
+
+ // Load text for task
+ if (FILE_READABLE($tpl)) {
+ // Load extension's own text template (HTML!)
+ $msg = LOAD_TEMPLATE("ext_".$ext, true);
+ } else {
+ // Load default message
+ $msg = LOAD_TEMPLATE("admin_new_ext", "", 0);
+ }
+
+ // Task not created so it's a brand-new extension which we need to register and create a task for!
+ $result_insert = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_task_system (assigned_admin, userid, status, task_type, subject, text, task_created)
+VALUES (%s,0,'NEW','EXTENSION','%s','%s',UNIX_TIMESTAMP())",
+ array(
+ $admin_id,
+ $subject,
+ addslashes($msg),
+ ), __FILE__, __LINE__, true, false
+ );
+ } // END - if
+
+ // Free memory
+ SQL_FREERESULT($result);
+}