/**
  * Recycle surveys - removes everything
  */
 public function recycle_surveys()
 {
     if ($this->course->has_resources(RESOURCE_SURVEY)) {
         $table_survey = Database::get_course_table(TABLE_SURVEY);
         $table_survey_q = Database::get_course_table(TABLE_SURVEY_QUESTION);
         $table_survey_q_o = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
         $table_survey_a = Database::get_course_Table(TABLE_SURVEY_ANSWER);
         $table_survey_i = Database::get_course_table(TABLE_SURVEY_INVITATION);
         $ids = implode(',', array_keys($this->course->resources[RESOURCE_SURVEY]));
         $sql = "DELETE FROM " . $table_survey_i . " WHERE c_id = " . $this->course_id . " ";
         Database::query($sql);
         $sql = "DELETE FROM " . $table_survey_a . " WHERE c_id = " . $this->course_id . "  AND survey_id IN(" . $ids . ")";
         Database::query($sql);
         $sql = "DELETE FROM " . $table_survey_q_o . " WHERE c_id = " . $this->course_id . "  AND survey_id IN(" . $ids . ")";
         Database::query($sql);
         $sql = "DELETE FROM " . $table_survey_q . " WHERE c_id = " . $this->course_id . "  AND survey_id IN(" . $ids . ")";
         Database::query($sql);
         $sql = "DELETE FROM " . $table_survey . " WHERE c_id = " . $this->course_id . "  AND survey_id IN(" . $ids . ")";
         Database::query($sql);
     }
 }
Example #2
0
/**
 * This function stores the Agenda Item in the table calendar_event and updates the item_property table also
 * @author: Patrick Cool <*****@*****.**>, Ghent University
 * @return integer the id of the last added agenda item
 */
function store_new_agenda_item()
{
    $_course = api_get_course_info();
    $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
    $t_agenda_repeat = Database::get_course_Table(TABLE_AGENDA_REPEAT);
    $course_id = api_get_course_int_id();
    // some filtering of the input data
    $title = trim($_POST['title']);
    // no html allowed in the title
    $content = trim($_POST['content']);
    $start_date = (int) $_POST['fyear'] . "-" . (int) $_POST['fmonth'] . "-" . (int) $_POST['fday'] . " " . (int) $_POST['fhour'] . ":" . (int) $_POST['fminute'] . ":00";
    $end_date = (int) $_POST['end_fyear'] . "-" . (int) $_POST['end_fmonth'] . "-" . (int) $_POST['end_fday'] . " " . (int) $_POST['end_fhour'] . ":" . (int) $_POST['end_fminute'] . ":00";
    $title = Database::escape_string($title);
    $content = Database::escape_string($content);
    $start_date = Database::escape_string($start_date);
    $end_date = Database::escape_string($end_date);
    if ($_POST['empty_end_date'] == 'on') {
        $end_date = "0000-00-00 00:00:00";
    }
    // store in the table calendar_event
    $sql = "INSERT INTO " . $TABLEAGENDA . " (c_id, title,content, start_date, end_date)\n\t\t\tVALUES ({$course_id}, '" . $title . "','" . $content . "', '" . $start_date . "','" . $end_date . "')";
    $result = Database::query($sql);
    $last_id = Database::insert_id();
    // store in last_tooledit (first the groups, then the users
    $to = $_POST['selectedform'];
    if (!is_null($to) || !empty($_SESSION['toolgroup'])) {
        // !is_null($to): when no user is selected we send it to everyone
        //$send_to=separate_users_groups($to);
        $send_to = separate_users_groups(explode('|', $to));
        // storing the selected groups
        if (is_array($send_to['groups'])) {
            foreach ($send_to['groups'] as $group) {
                api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", api_get_user_id(), $group, '', $start_date, $end_date);
            }
        }
        // storing the selected users
        if (is_array($send_to['users'])) {
            foreach ($send_to['users'] as $user) {
                api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", api_get_user_id(), '', $user, $start_date, $end_date);
            }
        }
    } else {
        // the message is sent to everyone, so we set the group to 0
        api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", api_get_user_id(), '', '', $start_date, $end_date);
    }
    // storing the resources
    store_resources($_SESSION['source_type'], $last_id);
    $course_id = api_get_course_int_id();
    //if repetitive, insert element into agenda_repeat table
    if (!empty($_POST['repeat']) && !empty($_POST['repeat_type'])) {
        if (!empty($_POST['repeat_end_year']) && !empty($_POST['repeat_end_month']) && !empty($_POST['repeat_end_day'])) {
            $end_y = intval($_POST['repeat_end_year']);
            $end_m = intval($_POST['repeat_end_month']);
            $end_d = intval($_POST['repeat_end_day']);
            $end = mktime((int) $_POST['fhour'], (int) $_POST['fminute'], 0, $end_m, $end_d, $end_y);
            $now = time();
            $type = Database::escape_string($_POST['repeat_type']);
            if ($end > $now && in_array($type, array('daily', 'weekly', 'monthlyByDate', 'monthlyByDay', 'monthlyByDayR', 'yearly'))) {
                $sql = "INSERT INTO {$t_agenda_repeat} (c_id, cal_id, cal_type, cal_end)" . " VALUES ({$course_id}, {$last_id},'{$type}',{$end})";
                $res = Database::query($sql);
            }
        }
    }
    return $last_id;
}