function process_form()
 {
     global $CFG, $page;
     unlink($this->imagepath);
     delete_records('lightboxgallery_image_meta', 'gallery', $this->gallery->id, 'image', $this->image);
     redirect($CFG->wwwroot . '/mod/lightboxgallery/view.php?l=' . $this->gallery->id . '&page=' . $page . '&editing=1');
 }
Example #2
0
function chat_delete_instance($id)
{
    /// Given an ID of an instance of this module,
    /// this function will permanently delete the instance
    /// and any data that depends on it.
    if (!($chat = get_record('chat', 'id', $id))) {
        return false;
    }
    $result = true;
    # Delete any dependent records here #
    if (!delete_records('chat', 'id', $chat->id)) {
        $result = false;
    }
    if (!delete_records('chat_messages', 'chatid', $chat->id)) {
        $result = false;
    }
    if (!delete_records('chat_users', 'chatid', $chat->id)) {
        $result = false;
    }
    $pagetypes = page_import_types('mod/chat/');
    foreach ($pagetypes as $pagetype) {
        if (!delete_records('block_instance', 'pageid', $chat->id, 'pagetype', $pagetype)) {
            $result = false;
        }
    }
    if (!delete_records('event', 'modulename', 'chat', 'instance', $chat->id)) {
        $result = false;
    }
    return $result;
}
 /**
  * Deletes this outcome from the database.
  * @param string $source from where was the object deleted (mod/forum, manual, etc.)
  * @return boolean success
  */
 function delete($source = null)
 {
     if (!empty($this->courseid)) {
         delete_records('grade_outcomes_courses', 'outcomeid', $this->id, 'courseid', $this->courseid);
     }
     return parent::delete($source);
 }
 /**
  * Processes the message (sends by email).
  * @param object $message the message to be sent
  */
 function send_message($message)
 {
     //send an email
     //if fails saved as read message
     //first try to get preference
     $usertoemail = get_user_preferences('message_processor_email_email', '', $message->useridto);
     //if fails use user profile default
     if ($usertoemail == NULL) {
         $userto = get_record('user', 'id', $message->useridto);
         $usertoemail = $userto->email;
     }
     $userfrom = get_record('user', 'id', $message->useridfrom);
     if (email_to_user($usertoemail, $userfrom->email, $message->subject, $message->fullmessage, $message->fullmessagehtml)) {
         /// Move the entry to the other table
         $message->timeread = time();
         $messageid = $message->id;
         unset($message->id);
         //if there is no more processor that want to process this can move message
         if (count_records('message_working', array('unreadmessageid' => $messageid)) == 0) {
             if (insert_record('message_read', $message)) {
                 delete_records('message', 'id', $messageid);
             }
         }
     } else {
         //delete what we've processed and check if can move message
         if (count_records('message_working', 'unreadmessageid', $messageid) == 0) {
             if (insert_record('message_read', $message)) {
                 delete_records('message', 'id', $messageid);
             }
         }
     }
     return true;
 }
Example #5
0
function deletepost_submit(Pieform $form, $values)
{
    global $SESSION, $postid, $goto;
    delete_records('blocktype_wall_post', 'id', $postid);
    $SESSION->add_ok_msg(get_string('deletepostsuccess', 'blocktype.wall'));
    redirect($goto);
}
Example #6
0
/**
* Delete a question from a quiz
*
* Deletes a question or a pagebreak from a quiz by updating $quiz
* as well as the quiz, quiz_question_instances
* @return boolean         false if the question was not in the quiz
* @param int $id          The id of the question to be deleted
* @param object $quiz  The extended quiz object as used by edit.php
*                         This is updated by this function
*/
function quiz_delete_quiz_question($id, &$quiz)
{
    // TODO: For the sake of safety check that this question can be deleted
    // safely, i.e., that it is not already in use.
    $questions = explode(",", $quiz->questions);
    // only do something if this question exists
    if (!isset($questions[$id])) {
        return false;
    }
    $question = $questions[$id];
    unset($questions[$id]);
    // If we deleted the question at the top and it was followed by
    // a page break then delete page break as well
    if ($id == 0 && count($questions) > 1 && $questions[1] == 0) {
        unset($questions[1]);
    }
    $quiz->questions = implode(",", $questions);
    // Avoid duplicate page breaks
    $quiz->questions = str_replace(',0,0', ',0', $quiz->questions);
    // save new questionlist in database
    if (!set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->instance)) {
        error('Could not save question list');
    }
    delete_records('quiz_question_instances', 'quiz', $quiz->instance, 'question', $question);
    return true;
}
Example #7
0
function deletefontform_submit(Pieform $form, $values)
{
    global $SESSION;
    $fontname = $values['font'];
    $result = delete_records('skin_fonts', 'name', $fontname);
    if ($result == false) {
        $SESSION->add_error_msg(get_string('cantdeletefont', 'skin'));
    } else {
        // Check to see if the font is being used in a skin. If it is remove it from
        // the skin's viewskin data
        $skins = get_records_array('skin');
        if (is_array($skins)) {
            foreach ($skins as $skin) {
                $options = unserialize($skin->viewskin);
                foreach ($options as $key => $option) {
                    if (preg_match('/font_family/', $key) && $option == $fontname) {
                        require_once get_config('docroot') . 'lib/skin.php';
                        $skinobj = new Skin($skin->id);
                        $viewskin = $skinobj->get('viewskin');
                        $viewskin[$key] = 'Arial';
                        // the default font
                        $skinobj->set('viewskin', $viewskin);
                        $skinobj->commit();
                    }
                }
            }
        }
        // Also delete all the files in the appropriate folder and the folder itself...
        $fontpath = get_config('dataroot') . 'skins/fonts/' . $fontname;
        recurse_remove_dir($fontpath);
        $SESSION->add_ok_msg(get_string('fontdeleted', 'skin'));
    }
    redirect('/admin/site/fonts.php');
}
Example #8
0
function xmldb_block_task_list_upgrade($oldversion = 0)
{
    $result = true;
    if ($result and $oldversion < 2007011501) {
        /// Define field format to be added to block_task_list
        $table = new XMLDBTable('block_task_list');
        $field = new XMLDBField('format');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'name');
        /// Launch add field format
        $result = $result and add_field($table, $field);
    }
    if ($result and $oldversion < 2007011503) {
        /// Manually remove bad capabilities
        $result = $result and delete_records('capabilities', 'name', 'block/tast_list:manage');
        $result = $result and delete_records('capabilities', 'name', 'block/tast_list:checkofftasks');
    }
    if ($result and $oldversion < 2007011505) {
        //TODO: The info field might be able to be removed, as it doesn't seem to be used anywhere, but in the meantime, change it to allow nulls
        /// Changing nullability of field info on table block_task_list to allow null
        $table = new XMLDBTable('block_task_list');
        $field = new XMLDBField('info');
        $field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'checked');
        /// Launch change of nullability for field info
        $result = $result && change_field_notnull($table, $field);
    }
    return $result;
}
Example #9
0
 public static function postinst($prevversion)
 {
     // Add blocktype category called 'survey' if it doesn't exists...
     ensure_record_exists('blocktype_category', (object) array('name' => 'survey'), (object) array('name' => 'survey'));
     if ($prevversion == 0) {
         // 1. Convert MyLearning artefacts to Survey artefacts (mhr_artefact table)...
         convert_artefacts_to_survey('multipleintelligences');
         convert_artefacts_to_survey('learningstyles');
         // 2. Install survey artefact blocktype named survey and later correctly convert block instances used in views...
         install_survey_blocktype();
         // 3. Convert block instances used in views (mhr_block_instance table)...
         convert_blocks_used_in_views('multipleintelligences');
         convert_blocks_used_in_views('learningstyles');
         // 4. Delete multipleintelligences and learningstyles blocks from mhr_blocktype_installed* tables...
         delete_records('blocktype_installed_viewtype', 'blocktype', 'multipleintelligences');
         delete_records('blocktype_installed_category', 'blocktype', 'multipleintelligences');
         delete_records('blocktype_installed_viewtype', 'blocktype', 'learningstyles');
         delete_records('blocktype_installed_category', 'blocktype', 'learningstyles');
         delete_records('blocktype_installed', 'artefactplugin', 'learning');
         // 5. Delete learning artefact from mhr_artefact_installed* tables...
         delete_records('artefact_installed_type', 'plugin', 'learning');
         delete_records('artefact_installed', 'name', 'learning');
         // 6. Recursive delete learning folder from htdocs/artefact/learning...
         recursive_folder_delete(get_config('docroot') . 'artefact/learning/');
     }
 }
function forumng_delete_instance($id, $ociskip = true)
{
    require_once dirname(__FILE__) . '/forum.php';
    try {
        $forum = forum::get_from_id($id, forum::CLONE_DIRECT);
        // avoid deleting OCI specific forum if running in upload block
        if ($ociskip) {
            global $restore;
            if (isset($restore) && $restore->restoreto == 0 && strpos($_SERVER['HTTP_REFERER'], 'blocks/versions/upload.php') !== false) {
                if ($forum->get_name() == get_string('newunitforumname', 'createcourse')) {
                    //Unit forum
                    echo ' found forumng ' . $forum->get_id() . ' ' . $forum->get_name();
                    return true;
                }
            }
        }
        $forum->delete_all_data();
        if (forum::search_installed()) {
            $cm = $forum->get_course_module();
            ousearch_document::delete_module_instance_data($cm);
        }
    } catch (Exception $e) {
        return false;
    }
    return delete_records('forumng', 'id', $id);
}
Example #11
0
/**
 * Given an ID of an instance of this module, 
 * this function will permanently delete the instance 
 * and any data that depends on it. 
 *
 * @param int $id Id of the module instance
 * @return boolean Success/Failure
 **/
function nanogong_delete_instance($id)
{
    global $CFG;
    if (!($nanogong = get_record("nanogong", "id", "{$id}"))) {
        return false;
    }
    $result = true;
    # Delete any dependent records here #
    if (!delete_records("nanogong", "id", "{$nanogong->id}")) {
        $result = false;
    }
    if ($nanogong_messages = get_records("nanogong_message", "nanogongid", "{$nanogong->id}")) {
        global $CFG;
        foreach ($nanogong_messages as $nanogong_message) {
            $soundfile = $CFG->dataroot . $nanogong_message->path;
            if (file_exists($soundfile)) {
                unlink($soundfile);
            }
        }
    }
    if (substr($CFG->release, 0, 3) == "1.9") {
        nanogong_grade_item_delete($nanagong);
    }
    if (!delete_records("nanogong_message", "nanogongid", "{$nanogong->id}")) {
        $result = false;
    }
    return $result;
}
Example #12
0
 public static function restore_data($data, $restore)
 {
     $linknamestatus = $linkurlstatus = false;
     foreach ($data as $datum) {
         switch ($datum->name) {
             case 'linkname':
                 // We just want to know that it is there
                 $linknamestatus = true;
                 break;
             case 'linkurl':
                 $content = $datum->value;
                 $result = restore_decode_content_links_worker($content, $restore);
                 if ($result != $content) {
                     $datum->value = addslashes($result);
                     if (debugging() and !defined('RESTORE_SILENTLY')) {
                         echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />';
                     }
                     $linkurlstatus = update_record('pagemenu_link_data', $datum);
                 } else {
                     $linkurlstatus = true;
                 }
                 break;
             default:
                 debugging('Deleting unknown data type: ' . $datum->name);
                 // Not recognized
                 delete_records('pagemenu_link_data', 'id', $datum->id);
                 break;
         }
     }
     return $linkurlstatus and $linknamestatus;
 }
 /**
  *	レコード削除 + 表示順を再構築
  */
 public static function delete_record($record)
 {
     if (!delete_records('sharing_cart', 'id', $record->id)) {
         return FALSE;
     }
     self::renumber($record->user);
     return TRUE;
 }
function delete_repository($id)
{
    if (delete_records("door_repository", "id", $id)) {
        return true;
    } else {
        return false;
    }
}
Example #15
0
function friend_user_delete($object_type, $event, $object)
{
    if (!empty($object->ident) && $object_type == "user" && $event == "delete") {
        delete_records('friends', 'owner', $object->ident);
        delete_records('friends', 'friend', $object->ident);
    }
    return $object;
}
Example #16
0
/**
 * Run scheduled tasks according to a cron spec.
 */
function elis_cron()
{
    global $CFG;
    require $CFG->dirroot . '/elis/core/lib/tasklib.php';
    $timenow = time();
    // get all tasks that are (over-)due
    $tasks = get_recordset_select('elis_scheduled_tasks', 'nextruntime <= ' . $timenow, 'nextruntime ASC');
    if (empty($tasks)) {
        return;
    }
    while ($task = rs_fetch_next_record($tasks)) {
        $starttime = microtime();
        mtrace("Running {$task->callfunction}({$task->taskname}) from {$task->plugin}...");
        if ($task->enddate !== null && $task->enddate < $timenow) {
            mtrace('* Cancelling task: past end date');
            delete_records('elis_scheduled_tasks', 'id', $task->id);
            continue;
        }
        // FIXME: check for blocking tasks
        // FIXME: check if task is locked
        // See if some other cron has already run the function while we were
        // doing something else -- if so, skip it.
        $nextrun = get_field('elis_scheduled_tasks', 'nextruntime', 'id', $task->id);
        if ($nextrun > $timenow) {
            mtrace('* Skipped (someone else already ran it)');
            continue;
        }
        // calculate the next run time
        $newtask = new stdClass();
        $newtask->id = $task->id;
        $newtask->lastruntime = time();
        $newtask->nextruntime = cron_next_run_time($newtask->lastruntime, (array) $task);
        // see if we have any runs left
        if ($task->runsremaining !== null) {
            $newtask->runsremaining = $task->runsremaining - 1;
            if ($newtask->runsremaining <= 0) {
                mtrace('* Cancelling task: no runs left');
                delete_records('elis_scheduled_tasks', 'id', $task->id);
            } else {
                update_record('elis_scheduled_tasks', $newtask);
            }
        } else {
            update_record('elis_scheduled_tasks', $newtask);
        }
        // load the file and call the function
        if ($task->callfile) {
            $callfile = $CFG->dirroot . $task->callfile;
            if (!is_readable($callfile)) {
                mtrace('* Skipped (file not found)');
                continue;
            }
            require_once $callfile;
        }
        call_user_func(unserialize($task->callfunction), $task->taskname);
        $difftime = microtime_diff($starttime, microtime());
        mtrace("* {$difftime} seconds");
    }
}
 function delete_records($id)
 {
     if (!delete_records('game_queries', 'attemptid', $id)) {
         error("Can't delete from game_queries attemptid={$id}");
     }
     if (!delete_records('game_cross', 'id', $id)) {
         error("Can't delete from game_cross id={$id}");
     }
 }
Example #18
0
File: lib.php Project: rrusso/EARS
 public function cleanup($semestersid)
 {
     // Clean up All the referral logs
     $semester = get_record('block_courseprefs_semesters', 'id', $semestersid);
     delete_records('block_student_referrals', 'semestersid', $semestersid);
     // Clean up all the teacher referral options on a section
     $sections = get_records('block_courseprefs_sections', 'semestersid', $semestersid);
     delete_records_select('block_teacher_referral_opt', 'sectionsid IN (' . implode(',', array_keys($sections)) . ')');
     return get_string('cleanup_hook', 'block_student_gradeviewer', $semester);
 }
 function process_form()
 {
     $caption = required_param('caption', PARAM_TEXT);
     $remove = optional_param('remove', '', PARAM_TEXT);
     if ($remove) {
         delete_records('lightboxgallery_image_meta', 'metatype', 'caption', 'gallery', $this->gallery->id, 'image', $this->image);
     } else {
         lightboxgallery_set_image_caption($this->gallery->id, $this->image, $caption);
     }
 }
/**
 * Given an ID of an instance of this module, 
 * this function will permanently delete the instance 
 * and any data that depends on it. 
 *
 * @param int $id Id of the module instance
 * @return boolean Success/Failure
 **/
function mindmap_delete_instance($id)
{
    if (!($mindmap = get_record("mindmap", "id", "{$id}"))) {
        return false;
    }
    $result = true;
    if (!delete_records("mindmap", "id", "{$mindmap->id}")) {
        $result = false;
    }
    return $result;
}
Example #21
0
 /**
  * Delete the temporary view
  */
 public static function cleanup(PluginImportLeap $importer)
 {
     if (self::$tempview) {
         if (self::$savetempview) {
             $title = get_string('entriesimportedfromleapexport', 'artefact.comment');
             set_field('view', 'title', $title, 'id', self::$tempview);
         } else {
             delete_records('view', 'id', self::$tempview);
         }
     }
 }
Example #22
0
/**
* Given an ID of an instance of this module, 
* this function will permanently delete the instance 
* and any data that depends on it.  
*
*/
function customlabel_delete_instance($id)
{
    if (!($customlabel = get_record('customlabel', 'id', "{$id}"))) {
        return false;
    }
    $result = true;
    if (!delete_records('customlabel', 'id', "{$customlabel->id}")) {
        $result = false;
    }
    return $result;
}
function xmldb_interaction_forum_upgrade($oldversion = 0)
{
    if ($oldversion < 2009062300) {
        foreach (array('topic', 'forum') as $type) {
            log_debug("Subscription upgrade for {$type}s");
            // Add missing primary key to the subscription tables
            // Step 1: remove duplicates
            if ($dupes = get_records_sql_array('
                SELECT "user", ' . $type . ', COUNT(*)
                FROM {interaction_forum_subscription_' . $type . '}
                GROUP BY "user", ' . $type . '
                HAVING COUNT(*) > 1', array())) {
                // We found duplicate subscriptions to a topic/forum
                foreach ($dupes as $dupe) {
                    log_debug("interaction.forum: Removing duplicate {$type} subscription for {$dupe->user}");
                    delete_records('interaction_forum_subscription_' . $type, 'user', $dupe->user, $type, $dupe->{$type});
                    insert_record('interaction_forum_subscription_' . $type, (object) array('user' => $dupe->user, $type => $dupe->{$type}));
                }
            }
            // Step 2: add the actual key
            $table = new XMLDBTable('interaction_forum_subscription_' . $type);
            $key = new XMLDBKey('primary');
            $key->setAttributes(XMLDB_KEY_PRIMARY, array('user', $type));
            add_key($table, $key);
            // Add a 'key' column, used for unsubscriptions
            $field = new XMLDBField('key');
            $field->setAttributes(XMLDB_TYPE_CHAR, 50, XMLDB_UNSIGNED, null);
            add_field($table, $field);
            $key = new XMLDBKey('keyuk');
            $key->setAttributes(XMLDB_KEY_UNIQUE, array('key'));
            add_key($table, $key);
            // Populate the key column
            if ($records = get_records_array('interaction_forum_subscription_' . $type, '', '', '', '"user", ' . $type)) {
                foreach ($records as $where) {
                    $new = (object) array('user' => $where->user, $type => $where->{$type}, 'key' => dechex(mt_rand()));
                    update_record('interaction_forum_subscription_' . $type, $new, $where);
                }
            }
            // Now make the key column not null
            $field->setAttributes(XMLDB_TYPE_CHAR, 50, XMLDB_UNSIGNED, XMLDB_NOTNULL);
            change_field_notnull($table, $field);
        }
    }
    if ($oldversion < 2009081700) {
        if (!get_record('interaction_config', 'plugin', 'forum', 'field', 'postdelay')) {
            insert_record('interaction_config', (object) array('plugin' => 'forum', 'field' => 'postdelay', 'value' => 30));
        }
    }
    if ($oldversion < 2009081800) {
        $subscription = (object) array('plugin' => 'forum', 'event' => 'creategroup', 'callfunction' => 'create_default_forum');
        ensure_record_exists('interaction_event_subscription', $subscription, $subscription);
    }
    return true;
}
Example #24
0
/**
 * Permanently delete the instance of the module and any data that depends on it.  
 *
 * @param int $id Instance id
 * @return bool
 */
function groupselect_delete_instance($id)
{
    if (!($groupselect = get_record('groupselect', 'id', $id))) {
        return false;
    }
    $result = true;
    if (!delete_records('groupselect', 'id', $groupselect->id)) {
        $result = false;
    }
    return $result;
}
Example #25
0
/**
 * Given an ID of an instance of this module, 
 * this function will permanently delete the instance 
 * and any data that depends on it. 
 *
 * @param int $id Id of the module instance
 * @return boolean Success/Failure
 **/
function slideshow_delete_instance($id)
{
    if (!($slideshow = get_record("slideshow", "id", "{$id}"))) {
        return false;
    }
    $result = true;
    # Delete any dependent records here #
    if (!delete_records("slideshow", "id", "{$slideshow->id}")) {
        $result = false;
    }
    return $result;
}
/**
 * Given an ID of an instance of this module, 
 * this function will permanently delete the instance 
 * and any data that depends on it. 
 *
 * @param int $id Id of the module instance
 * @return boolean Success/Failure
 **/
function mplayer_delete_instance($id)
{
    if (!($mplayer = get_record("mplayer", "id", "{$id}"))) {
        return false;
    }
    $result = true;
    # Delete any dependent records here #
    if (!delete_records("mplayer", "id", "{$mplayer->id}")) {
        $result = false;
    }
    return $result;
}
Example #27
0
function openmeetings_delete_instance($id)
{
    if (!($openmeetings = get_record("openmeetings", "id", "{$id}"))) {
        return false;
    }
    $result = true;
    # Delete any dependent records here #
    if (!delete_records("openmeetings", "id", "{$openmeetings->id}")) {
        $result = false;
    }
    return $result;
}
Example #28
0
/**
 * Given an ID of an instance of this module, 
 * this function will permanently delete the instance 
 * and any data that depends on it. 
 *
 * @param int $id Id of the module instance
 * @return boolean Success/Failure
 **/
function poodllpairwork_delete_instance($id)
{
    if (!($pairwork = get_record("poodllpairwork", "id", "{$id}"))) {
        return false;
    }
    $result = true;
    # Delete any dependent records here #
    if (!delete_records("poodllpairwork", "id", "{$pairwork->id}")) {
        $result = false;
    }
    return $result;
}
Example #29
0
function lightboxgallery_delete_instance($id)
{
    if ($gallery = get_record('lightboxgallery', 'id', $id)) {
        $result = true;
        $result = $result && delete_records('lightboxgallery', 'id', $gallery->id);
        $result = $result && delete_records('lightboxgallery_comments', 'gallery', $gallery->id);
        $result = $result && delete_records('lightboxgallery_image_meta', 'gallery', $gallery->id);
    } else {
        $result = false;
    }
    return $result;
}
Example #30
0
/**
 * Given an ID of an instance of this module,
 * this function will permanently delete the instance
 * and any data that depends on it.
 *
 * @param int $id Id of the module instance
 * @return boolean Success/Failure
 */
function deva_delete_instance($id)
{
    if (!($deva = get_record('deva', 'id', $id))) {
        return false;
    }
    $result = true;
    # Delete any dependent records here #
    if (!delete_records('deva', 'id', $deva->id)) {
        $result = false;
    }
    return $result;
}