Example #1
0
/**
 * Create a new entry in the facetoface_sessions table
 */
function facetoface_add_session($session, $sessiondates, $fromform) {
    global $USER, $DB, $CFG;
     //$face2face=$DB->get_record('facetoface',array('id'=>$session->facetoface));
     //$actual_sessions=$face2face->actualsessions+1;
     //print_object($face2face);exit;
    $session->timecreated = time();
    $session = cleanup_session_data($session);
    $wiziq=new stdClass();
   
   
    if (empty($sessiondates)) {
        // Insert a dummy date record.
        $date = new stdClass();
        $date->sessionid =  $new_session;
        $date->timestart = 0;
        $date->timefinish = 0;
        $date->sessiontimezone = '';
			//commented by niranjan for adding session in multiple dates
      // $DB->insert_record('facetoface_sessions_dates', $date); 
    } else {
        foreach ($sessiondates as $date) {
			//Niranjan added this to add session in date loop
			$new_session= $DB->insert_record('facetoface_sessions', $session);
            $date->sessionid =  $new_session;
			$wiziq->wiziq_datetime=$date->timestart;
			$wiziq->wiziq_timezone=$date->sessiontimezone;
			$wiziq->class_timezone=$date->sessiontimezone;
			
		    $DB->insert_record('facetoface_sessions_dates', $date);
			
			if (!facetoface_save_session_room($new_session, $fromform)) {
       
               print_error('error:couldnotsaveroom', 'facetoface');
            }
			/*If online session is enabled. */
        if($session->onlinesession ==1){
            require_once($CFG->dirroot.'/mod/wiziq/locallib.php');
		    require_once($CFG->dirroot . '/course/modlib.php');

              $wiziq->name=$DB->get_field('facetoface','name',array('id'=>$session->facetoface));
              $wiziq->modulename='wiziq';
              $wiziq->course=1;
              $wiziq->duration=$session->duration;
              $wiziq->timezone=wiziq_timezone();
             //$wiziq->wiziq_timezone='Asia/Kolkata'; 
            //  $wiziq->class_timezone = 'Asia/Kolkata';
              $wiziq->timenow=time();
              $wiziq->datetime=time();
              $wiziq->recording=1;
              $wiziq->groupinid=0;
              $wiziq->module=$DB->get_field('modules','id',array('name'=>$wiziq->modulename));;
              $wiziq->section=1;
              $wiziq->batchid=$session->facetoface;
              $wiziq->sessionid=$new_session;
              $wiziq->visible=1;
	
               $courseid = $DB->get_record('course', array('id'=>$wiziq->course), '*', MUST_EXIST);
              add_moduleinfo($wiziq, $courseid, $mform = null);
              //$wiziq= wiziq_add_instance($wiziq, $mform = null);
       
        
           }
       
   
	
    /**
 * Add a record to the facetoface submissions table and sends out an
 * email confirmation
 *
 * @param class $session record from the facetoface_sessions table
 * @param class $facetoface record from the facetoface table
 * @param class $course record from the course table
 * @param string $discountcode code entered by the user
 * @param integer $notificationtype type of notifications to send to user
 * @see {{MDL_F2F_INVITE}}
 * @param integer $statuscode Status code to set
 * @param integer $userid user to signup
 * @param bool $notifyuser whether or not to send an email confirmation
 *
 * facetoface_user_signup($session, $facetoface, $course, $discountcode,
                                $notificationtype, $statuscode, $userid = false,
                                $notifyuser = true) {
                                  $users = facetoface_get_attendees($session->id);

    if ($users) {
        // No/deleted session dates
        if (empty($session->datetimeknown)) {

            // Convert any bookings to waitlists
            foreach ($users as $user) {
                if ($user->statuscode == MDL_F2F_STATUS_BOOKED) {

                    if (!facetoface_user_signup($session, $facetoface, $course, $user->discountcode, $user->notificationtype, MDL_F2F_STATUS_WAITLISTED, $user->id)) {
                        // rollback_sql();
                        return false;
                    }
                }
            }
            $eventtype = $user->statuscode == MDL_F2F_STATUS_BOOKED ? 'booking' : 'session';
 * @param bool $displayerrors whether or not to return an error page on errors*/
   /*==========================Started by rajut for batch users are assigne as signup users (date:17-11-2015)==========*/        
    $assigned_users=$DB->get_records_sql("SELECT * FROM {local_batch_users} WHERE f2fid=$session->facetoface");
     $assigned_course=$DB->get_records_sql("SELECT * FROM {local_batch_courses} WHERE batchid=$session->facetoface");
   
    $newsession=$DB->get_record('facetoface_sessions',array('id'=>$new_session));
    $face2face=$DB->get_record('facetoface',array('id'=>$session->facetoface));
  
     //print_object($assigned_users);
 
        foreach($assigned_users as $assigned_user){
            $course=$DB->get_record('course',array('id'=>$assigned_course->courseid));
            $statuscode = MDL_F2F_STATUS_BOOKED;
            $notifytype = ((int)$notificationtype == MDL_F2F_NONE ? false : true);
             facetoface_user_signup($newsession,$face2face,$course,$discountcode,
                                    $notifytype,$statuscode,$assigned_user->userid,
                                    $notifyuser = false);
             
             
        }
        //* Strated by rajut no.of sessions avialble for batch update in fcae2fcae table when each session created o batch*//
        $total_sessions=$DB->get_field_sql("SELECT count(id) FROM {facetoface_sessions} where facetoface=$session->facetoface");
        if($total_sessions){
              $DB->execute('update {facetoface} SET totalsessions='.$total_sessions.' WHERE id='.$session->facetoface.'');
        }
        //print_object($face2face);exit;
        if($face2face){
             $actual_sessions=$face2face->actualsessions+1;
             $DB->execute('update {facetoface} SET actualsessions='.$actual_sessions.' WHERE id='.$session->facetoface.'');
        }
          //* Ended by rajut no.of sessions avialble for batch update in fcae2fcae table when each session created o batch*//
       /*==========================ended by rajut for batch users are assigne as signup users (date:17-11-2015)==========*/ 
	    } /* End of the dates loop */
	  } 
	  /* End of the else loop */
   
    return $new_session;
}
Example #2
0
 /**
  * Defines the structure for wiziq mod_form.
  */
 public function definition() {
     /* @var $COURSE type */
     global $CFG, $OUTPUT, $COURSE, $USER, $DB;
     $mform = $this->_form;
     $schedulenewwiziqclass = html_writer::link(
             new moodle_url("$CFG->wwwroot/course/modedit.php",
             array('add' => 'wiziq', 'type' => '', 'course' => $COURSE->id,
                 'section' => '0', 'return' => '0')),
             get_string('schedule_class', 'wiziq'));
     $navigation_tabs_manage = html_writer::link(
             new moodle_url("$CFG->wwwroot/mod/wiziq/index.php",
             array('id' => $COURSE->id, 'sesskey' => sesskey())),
             get_string('manage_classes', 'wiziq'));
     $navigation_tabs_content = html_writer::link(
             new moodle_url("$CFG->wwwroot/mod/wiziq/content.php",
             array('id' => $COURSE->id, 'sesskey' => sesskey())),
             get_string('manage_content', 'wiziq'));
     $table_html_p1 = '<table>'.'<tr><th>'.$schedulenewwiziqclass.'</a></th><th>|</th>';
     $table_html_p2 ='<th>'.$navigation_tabs_manage.'</th><th>|</th>';
     $table_html_p3 ='<th>'.$navigation_tabs_content.'</th></tr>';
     $table_html = $table_html_p1.$table_html_p2.$table_html_p3;
     $mform->addElement('html', $table_html);
     $mform->addElement('html', '</td></tr></table>');
     //-------------------------------------------------------------------------------
     // Adding the "general" fieldset, where all the common settings are showed
     $mform->addElement('header', 'general', get_string('general', 'form'));
     // Adding the standard "name" field
     $mform->addElement('text', 'name', get_string('wiziqname', 'wiziq'), array('size'=>'64'));
     if (!empty($CFG->formatstringstriptags)) {
         $mform->setType('name', PARAM_TEXT);
     } else {
         $mform->setType('name', PARAM_RAW);
     }
     $mform->addElement('hidden', 'class_id', "");
     $mform->setType('class_id', PARAM_INT);
     $mform->addElement('hidden', 'lasteditorid', "");
     $mform->setType('lasteditorid', PARAM_INT);
     $mform->addRule('name', null, 'required', null, 'client');
     $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
     $mform->addHelpButton('name', 'wiziqname', 'wiziq');
     // Adding the standard "intro" and "introformat" fields
     $this->add_intro_editor();
     //-------------------------------------------------------------------------------
     // Adding the rest of wiziq settings, spreeading all them into this fieldset
     // or adding more fieldsets ('header' elements) if needed for better logic
     $mform->addElement('header', 'wiziqdatetimesetting',
             get_string('wiziqdatetimesetting', 'wiziq'));
     $vctime = wiziq_timezone();
     $wiziq_timezone_select = $mform->addElement('select', 'wiziq_timezone',
             get_string('vc_class_timezone', 'wiziq'), $vctime);
     if (isset($_COOKIE['wiziq_vctimezone'])) {
         $wiziq_vc_timezone_cookie = $_COOKIE['wiziq_vctimezone'];
         $wiziq_timezone_select->setSelected($wiziq_vc_timezone_cookie);
     }
     $mform->addHelpButton('wiziq_timezone', 'vc_class_timezone', 'wiziq');
     $mform->addElement('checkbox', 'schedule_for_now', get_string('schedule_for_now', 'wiziq'));
     $mform->setDefault('schedule_for_now', false);
     $mform->addHelpButton('schedule_for_now', 'schedule_for_now', 'wiziq');
     $mform->addElement('hidden', 'timenow', time());
     $mform->setType('timenow', PARAM_INT);
     $dtoption = array(
             'startyear' => 1970,
             'stopyear'  => 2020,
             'timezone'  => 99,
             'applydst'  => true,
             'step'      => 1,
             'optional' => false
         );
     $mform->addelement('date_time_selector', 'wiziq_datetime',
             get_string('wiziq_datetime', 'wiziq'), $dtoption);
     $mform->addHelpButton('wiziq_datetime', 'wiziq_datetime', 'wiziq');
     $mform->disabledIf('wiziq_datetime', 'schedule_for_now', 'checked');
     $mform->addElement('text', 'duration', get_string('wiziq_duration', 'wiziq'));
     $mform->setType('duration', PARAM_INT);
     $mform->addRule('duration', get_string('duration_req', 'wiziq'),
             'required', null, 'client', true);
     $mform->addRule('duration', get_string('duration_number', 'wiziq'),
             'numeric', null, 'client');
     $mform->setDefault('duration', 30);
     $mform->addHelpButton('duration', 'duration', 'wiziq');
     $mform->addElement('header', 'wiziqclasssettings',
             get_string('wiziqclasssettings', 'wiziq'));
     $vclang = wiziq_languagexml();
     $wiziq_language_select = $mform->addElement('select', 'vc_language',
             get_string('vc_language', 'wiziq'), $vclang);
     if (isset($_COOKIE['wiziq_vclanguage'])) {
         $wiziq_vc_cookie = $_COOKIE['wiziq_vclanguage'];
         $wiziq_language_select->setSelected($wiziq_vc_cookie);
     }
     $mform->addHelpButton('vc_language', 'vc_language', 'wiziq');
     $recordingtype = array();
     $recordingtype[] = $mform->createElement('radio', 'recording', '',
             get_string('record', 'wiziq'), 1);
     $recordingtype[] = $mform->createElement('radio', 'recording', '',
             get_string('dontrecord', 'wiziq'), 0);
     $mform->setDefault('recording', 1);
     $mform->addGroup($recordingtype, 'recordingtype',
             get_string('recording_option', 'wiziq'), array(' '), false);
     $mform->addHelpButton('recordingtype', 'recordingtype', 'wiziq');
     //TODO: Import list of teacher for this course --- done
     $courseid = $COURSE->id;
     if (is_siteadmin($USER->id)) {
         $teacherdetail = wiziq_getteacherdetail($courseid);
         if (!empty($teacherdetail)) {
             $mform->addElement('checkbox', 'scheduleforother',
                     get_string('scheduleforother', 'wiziq'));
             $mform->setDefault('scheduleforother', false);
             $mform->addHelpButton('scheduleforother', 'scheduleforother', 'wiziq');
             $teacher = array();
             $teacher['select'] = '[select]';
             foreach ($teacherdetail as $value) {
                 $teacher[$value->id] = $value->username;
             }
             $mform->addElement('select', 'presenter_id',
                     get_string('presenter_id', 'wiziq'), $teacher);
             $mform->disabledIf('presenter_id', 'scheduleforother', 'notchecked');
         }
     }
     //-------------------------------------------------------------------------------
     // add standard elements, common to all modules
     $this->standard_coursemodule_elements();
     //-------------------------------------------------------------------------------
     // add standard buttons, common to all modules
     $this->add_action_buttons();
 }