Exemplo n.º 1
0
/**
 * Save imported class data to database
 */
function save_data($classes)
{
    $number_of_added_classes = 0;
    foreach ($classes as $index => $class) {
        if (ClassManager::create_class($class['ClassName'])) {
            $number_of_added_classes++;
        }
    }
    return $number_of_added_classes;
}
Exemplo n.º 2
0
 public function testMock()
 {
     $manager = ClassManager::getInstance();
     $manager->register('StaticMock\\MethodReplacer\\A', 'a', function () {
         return 3;
     });
     $manager->register('StaticMock\\MethodReplacer\\B', 'b', function () {
         return 4;
     });
     $this->assertEquals(3, A::a());
     $this->assertEquals(4, B::b());
     $manager->deregister('StaticMock\\MethodReplacer\\A', 'a');
     $manager->deregister('StaticMock\\MethodReplacer\\B', 'b');
     $this->assertEquals(1, A::a());
     $this->assertEquals(2, B::b());
 }
    $first_letter_course = $_POST['firstLetterCourse'];
    if ($form_sent == 1) {
        if (count($classes) == 0 || count($courses) == 0) {
            Display::display_error_message(get_lang('AtLeastOneClassAndOneCourse'));
        } elseif (api_substr($_POST['formSubmit'], -2) == '>>') {
            foreach ($courses as $course_code) {
                foreach ($classes as $class_id) {
                    ClassManager::subscribe_to_course($class_id, $course_code);
                }
            }
            Display::display_normal_message(get_lang('ClassesSubscribed'));
        } else {
            // remove classes from courses
            foreach ($courses as $course_code) {
                foreach ($classes as $class_id) {
                    ClassManager::unsubscribe_from_course($class_id, $course_code);
                }
            }
            Display::display_normal_message(get_lang('ClassesUnSubscribed'));
        }
    }
}
$sql = "SELECT id,name FROM {$tbl_class} WHERE name LIKE '" . $first_letter_class . "%' ORDER BY " . (count($classes) > 0 ? "(id IN('" . implode("','", $classes) . "')) DESC," : "") . " name";
$result = Database::query($sql);
$db_classes = Database::store_result($result);
$sql = "SELECT code,visual_code,title FROM {$tbl_course} WHERE visual_code LIKE '" . $first_letter_course . "%' ORDER BY " . (count($courses) > 0 ? "(code IN('" . implode("','", $courses) . "')) DESC," : "") . " visual_code";
$result = Database::query($sql);
$db_courses = Database::store_result($result);
if (!empty($error_message)) {
    Display::display_normal_message($error_message);
}
Exemplo n.º 4
0
        // Delete selected classes
        case 'delete_classes':
            $classes = $_POST['class'];
            if (count($classes) > 0) {
                foreach ($classes as $index => $class_id) {
                    ClassManager::delete_class($class_id);
                }
                $message = Display::return_message(get_lang('ClassesDeleted'));
            }
            break;
    }
}
if (isset($_GET['action'])) {
    switch ($_GET['action']) {
        case 'delete_class':
            ClassManager::delete_class($_GET['class_id']);
            $message = Display::return_message(get_lang('ClassDeleted'));
            break;
        case 'show_message':
            $message = Display::return_message(Security::remove_XSS(stripslashes($_GET['message'])));
            break;
    }
}
// Create a search-box
$form = new FormValidator('search_simple', 'get', '', '', null, false);
$renderer =& $form->defaultRenderer();
$renderer->setElementTemplate('<span>{element}</span> ');
$form->addElement('text', 'keyword', get_lang('keyword'));
$form->addElement('button', 'submit', get_lang('Search'));
$content .= $form->return_form();
// Create the sortable table with class information
Exemplo n.º 5
0
// Resetting the course id.
$cidReset = true;
// Including some necessary dokeos files.
require_once '../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH) . 'classmanager.lib.php';
// Setting the section (for the tabs).
$this_section = SECTION_PLATFORM_ADMIN;
// Access restrictions.
api_protect_admin_script();
// Setting breadcrumbs.
$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array('url' => 'class_list.php', 'name' => get_lang('AdminClasses'));
// Setting the name of the tool.
$tool_name = get_lang('AddClasses');
$tool_name = get_lang('ModifyClassInfo');
$class_id = intval($_GET['idclass']);
$class = ClassManager::get_class_info($class_id);
$form = new FormValidator('edit_class', 'post', 'class_edit.php?idclass=' . $class_id);
$form->add_textfield('name', get_lang('ClassName'));
$form->addElement('style_submit_button', 'submit', get_lang('Ok'), 'class="add"');
$form->setDefaults(array('name' => $class['name']));
if ($form->validate()) {
    $values = $form->exportValues();
    ClassManager::set_name($values['name'], $class_id);
    header('Location: class_list.php');
}
Display::display_header($tool_name);
//api_display_tool_title($tool_name);
$form->display();
// Displaying the footer.
Display::display_footer();
        if ($add_to_class) {
            if (count($left_user_list) == 0) {
                $error_message = get_lang('AtLeastOneUser');
            } else {
                foreach ($left_user_list as $user_id) {
                    ClassManager::add_user($user_id, $class_id);
                }
                header('Location: class_list.php?filtreCours=' . urlencode($course));
                exit;
            }
        } elseif ($remove_from_class) {
            if (count($right_user_list) == 0) {
                $error_message = get_lang('AtLeastOneUser');
            } else {
                foreach ($right_user_list as $index => $user_id) {
                    ClassManager::unsubscribe_user($user_id, $class_id);
                }
                header('Location: class_list.php?filtreCours=' . urlencode($course));
                exit;
            }
        }
    }
}
Display::display_header($tool_name);
//api_display_tool_title($tool_name);
$target_name = api_sort_by_first_name() ? 'firstname' : 'lastname';
$sql = "SELECT u.user_id,lastname,firstname,username FROM {$tbl_user} u LEFT JOIN {$tbl_class_user} cu ON u.user_id=cu.user_id AND class_id='{$class_id}' WHERE " . $target_name . " LIKE '" . $first_letter_left . "%' AND class_id IS NULL ORDER BY " . (count($left_user_list) > 0 ? "(user_id IN(" . implode(',', $left_user_list) . ")) DESC," : "") . " " . $target_name;
$result = Database::query($sql);
$left_users = Database::store_result($result);
$sql = "SELECT u.user_id,lastname,firstname,username FROM {$tbl_user} u,{$tbl_class_user} cu WHERE cu.user_id=u.user_id AND class_id='{$class_id}' AND " . $target_name . " LIKE '" . $first_letter_right . "%' ORDER BY " . (count($right_user_list) > 0 ? "(user_id IN(" . implode(',', $right_user_list) . ")) DESC," : "") . " " . $target_name;
$result = Database::query($sql);
Exemplo n.º 7
0
            $row[] = "<span title='{$username}'>" . $user['lastname'] . "</span>";
            $row[] = $user['firstname'];
        }
        $row[] = Display::encrypted_mailto_link($user['email'], $user['email']);
        $row[] = $user['status'] == 5 ? get_lang('Student') : get_lang('Teacher');
        $row[] = '<a href="user_information.php?user_id=' . $user['user_id'] . '">' . Display::return_icon('synthese_view.gif', get_lang('Info')) . '</a>';
        $data[] = $row;
    }
    Display::display_sortable_table($table_header, $data, array(), array(), array('id' => $_GET['id']));
} else {
    echo get_lang('NoUsersInClass');
}
/**
 * Show all courses in which this class is subscribed.
 */
$courses = ClassManager::get_courses($class_id);
if (count($courses) > 0) {
    $header[] = array(get_lang('Code'), true);
    $header[] = array(get_lang('Title'), true);
    $header[] = array('', false);
    $data = array();
    foreach ($courses as $index => $course) {
        $row = array();
        $row[] = $course['visual_code'];
        $row[] = $course['title'];
        $row[] = '<a href="course_information.php?code=' . $course['code'] . '">' . Display::return_icon('info_small.gif', get_lang('Delete')) . '</a>' . '<a href="' . api_get_path(WEB_COURSE_PATH) . $course['directory'] . '">' . Display::return_icon('course_home.gif', get_lang('CourseHome')) . '</a>' . '<a href="course_edit.php?course_code=' . $course['code'] . '">' . Display::return_icon('edit.gif', get_lang('Edit')) . '</a>';
        $data[] = $row;
    }
    echo '<p><b>' . get_lang('Courses') . '</b></p>';
    echo '<blockquote>';
    Display::display_sortable_table($header, $data, array(), array(), array('id' => $_GET['id']));
Exemplo n.º 8
0
 function main()
 {
     $Register =& Register::getInstance();
     $smarty =& $Register->get(VAR_SMARTY);
     /*@var $smarty Smarty*/
     // shopping cart
     //iframe cookie security workaround
     if (isset($_GET['check_cookie'])) {
         if ($_GET['check_cookie'] != session_id()) {
             $productID = (int) $_GET['productID'];
             $product_data = GetProduct($productID);
             $product_slug = $product_data && isset($product_data['slug']) ? $product_data['slug'] : '';
             $url = "?ukey=product_widget&productID={$productID}&product_slug={$product_slug}&check_cookie&";
             $widgets = false;
             $Register->set('widgets', $widgets);
             $_SERVER['REQUEST_URI'] = preg_replace('/(^|&)widgets=1/', '', $_SERVER['REQUEST_URI']);
             RedirectSQ($url);
         } else {
             renderURL('check_cookie&productID', '', true);
         }
     }
     if (isset($_GET["make_more_exact_cart_content"])) {
         $smarty->assign("make_more_exact_cart_content", 1);
     }
     if (isset($_GET["remove"]) && $_GET["remove"] > 0) {
         //remove from cart product with productID == $remove
         $cartEntry = new ShoppingCart();
         $cartEntry->loadCurrentCart();
         $cartEntry->setItemQuantity($_GET['remove'], 0);
         $cartEntry->saveCurrentCart();
         if ($cartEntry->isEmpty()) {
             //remove coupon from empty cart
             ClassManager::includeClass('discount_coupon');
             discount_coupon::remove();
         }
         RedirectSQ('remove=');
     }
     $cart_view = $this->_detect_cart_view();
     if (isset($_POST["update"]) || isset($_POST["recalculate"])) {
         //update shopping cart content
         if ($_POST['discount_coupon_code'] != '') {
             $this->_check_and_apply_coupon($_POST['discount_coupon_code']);
         }
         $cartEntry = new ShoppingCart();
         $cartEntry->loadCurrentCart();
         $upd_data = scanArrayKeysForID($_POST, 'count');
         foreach ($upd_data as $_itemID => $_data) {
             $cartEntry->setItemQuantity($_itemID, intval($_data['count']));
         }
         $cartEntry->saveCurrentCart();
         if ($cartEntry->isEmpty()) {
             //remove coupon from empty cart
             ClassManager::includeClass('discount_coupon');
             discount_coupon::remove();
         }
         if (cartCheckMinOrderAmount() && cartCheckMinTotalOrderAmount()) {
             switch ($cart_view) {
                 case CARTVIEW_FRAME:
                     if (isset($_POST['checkout']) && $Register->get('store_mode') == 'facebook') {
                         $store_mode = false;
                         $Register->set('store_mode', $store_mode);
                         $jsgoto = '?ukey=checkout&view=noframe';
                         RedirectSQ($jsgoto ? 'jsgoto=' . base64_encode(set_query($jsgoto)) : '');
                     }
                     RedirectSQ(isset($_POST['checkout']) ? '?ukey=checkout' : (isset($_POST['ppe_checkout_x']) ? 'ppexpresscheckout2=1' : (isset($_POST['google_checkout_x']) ? 'googlecheckout2=1' : '')));
                     break;
                 case CARTVIEW_WIDGET:
                 case CARTVIEW_FADE:
                     $jsgoto = isset($_POST['checkout']) ? '?ukey=checkout&view=noframe' : (isset($_POST['ppe_checkout_x']) ? 'ppexpresscheckout2=1&view=frame' : (isset($_POST['google_checkout_x']) ? 'googlecheckout2=1&view=frame' : ''));
                     RedirectSQ($jsgoto ? 'jsgoto=' . base64_encode(set_query($jsgoto)) : '');
                     break;
             }
         } elseif (isset($_POST['checkout']) || isset($_POST['google_checkout_x']) || isset($_POST['ppe_checkout_x'])) {
             $smarty->assign('cart_error_show', '1');
         }
     }
     if (isset($_GET["clear_cart"])) {
         //completely clear shopping cart
         $cartEntry = new ShoppingCart();
         $cartEntry->loadCurrentCart();
         $cartEntry->cleanCurrentCart('erase');
         //remove coupon from empty cart
         ClassManager::includeClass('discount_coupon');
         discount_coupon::remove();
         RedirectSQ('clear_cart=');
     }
     if (isset($_POST['checkout'])) {
         if (SystemSettings::is_hosted() && file_exists(WBS_DIR . '/kernel/classes/class.metric.php')) {
             include_once WBS_DIR . '/kernel/classes/class.metric.php';
             $DB_KEY = SystemSettings::get('DB_KEY');
             $U_ID = sc_getSessionData('U_ID');
             $metric = metric::getInstance();
             $metric->addAction($DB_KEY, $U_ID, 'SC', 'CHECKOUT', isset($_GET['widgets']) ? 'WIDGET' : 'STOREFRONT', '');
         }
     }
     $resCart = cartGetCartContent();
     $resDiscount = dscGetCartDiscounts($resCart["total_price"], isset($_SESSION["log"]) ? $_SESSION["log"] : "");
     $currencyEntry = Currency::getSelectedCurrencyInstance();
     $cart_discount_show = $resDiscount['other_discounts']['cu'] > 0 ? $currencyEntry->getView($resDiscount['other_discounts']['cu']) : '';
     $coupon_discount_show = $resDiscount['coupon_discount']['cu'] > 0 ? $currencyEntry->getView($resDiscount['coupon_discount']['cu']) : '';
     $smarty->assign("cart_content", xHtmlSpecialChars($resCart["cart_content"], null, 'name'));
     $smarty->assign("cart_amount", $resCart["total_price"] - $resDiscount["discount_standart_unit"]);
     $smarty->assign('cart_min', show_price(CONF_MINIMAL_ORDER_AMOUNT));
     $smarty->assign("cart_total", $currencyEntry->getView($resDiscount['total']['cu']));
     $smarty->assign('cart_discount', $cart_discount_show);
     $smarty->assign('discount_percent', round($resDiscount['discount_percent'], 1));
     $smarty->assign('coupon_discount', $coupon_discount_show);
     $smarty->assign("current_coupon", discount_coupon::getCurrentCoupon());
     if (isset($_SESSION['log'])) {
         $smarty->assign('shippingAddressID', regGetDefaultAddressIDByLogin($_SESSION['log']));
     }
     if (isset($_GET['min_order'])) {
         $smarty->assign('minOrder', 'error');
     }
     if (isset($_GET['jsgoto'])) {
         $smarty->assign('jsgoto', base64_decode($_GET['jsgoto']));
     }
     $smarty->assign('main_content_template', 'shopping_cart.html');
     $smarty->assign('main_body_style', 'style="' . (CONF_SHOPPING_CART_VIEW == 2 || $cart_view == CARTVIEW_FRAME ? '' : 'background:#FFFFFF;') . 'min-width:auto;width:auto;_width:auto;"');
 }
Exemplo n.º 9
0
 public function writeObject($obj)
 {
     $class = get_class($obj);
     $alias = ClassManager::getClassAlias($class);
     if (isset($this->classref[$alias])) {
         $index = $this->classref[$alias];
     } else {
         $reflector = new \ReflectionClass($obj);
         $props = $reflector->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED | \ReflectionProperty::IS_PRIVATE);
         $index = $this->writeClass($alias, $props);
     }
     $this->refer->set($obj);
     $props = $this->propsref[$index];
     $this->stream->write(Tags::TagObject . $index . Tags::TagOpenbrace);
     foreach ($props as $prop) {
         $this->serialize($prop->getValue($obj));
     }
     $this->stream->write(Tags::TagClosebrace);
 }
Exemplo n.º 10
0
/**
 * Save the imported data
 */
function save_data($users)
{
    $user_table = Database::get_main_table(TABLE_MAIN_USER);
    if (is_array($users)) {
        foreach ($users as $index => $user) {
            $user = complete_missing_data($user);
            $user['Status'] = api_status_key($user['Status']);
            $user_id = UserManager::create_user($user['FirstName'], $user['LastName'], $user['Status'], $user['Email'], $user['UserName'], $user['Password'], $user['OfficialCode'], api_get_setting('PlatformLanguage'), $user['PhoneNumber'], '', $user['AuthSource']);
            foreach ($user['Courses'] as $index => $course) {
                if (CourseManager::course_exists($course)) {
                    CourseManager::subscribe_user($user_id, $course, $user['Status']);
                }
            }
            if (strlen($user['ClassName']) > 0) {
                $class_id = ClassManager::get_class_id($user['ClassName']);
                ClassManager::add_user($user_id, $class_id);
            }
            // TODO: Hard-coded French texts.
            // Qualite
            if (!empty($user['Qualite'])) {
                UserManager::update_extra_field_value($user_id, 'qualite', $user['Qualite']);
            }
            // Categorie
            if (!empty($user['Categorie'])) {
                UserManager::update_extra_field_value($user_id, 'categorie', $user['Categorie']);
            }
            // Etat
            if (!empty($user['Etat'])) {
                UserManager::update_extra_field_value($user_id, 'etat', $user['Etat']);
            }
            // Niveau
            if (!empty($user['Niveau'])) {
                UserManager::update_extra_field_value($user_id, 'niveau', $user['Niveau']);
            }
        }
    }
}
Exemplo n.º 11
0
 /**
  * Unsubscribe a user from a class. If the class is also subscribed in a
  * course, the user will be unsubscribed from that course
  * @param int $user_id The user id
  * @param int $class_id The class id
  */
 public static function unsubscribe_user($user_id, $class_id)
 {
     $class_id = intval($class_id);
     $user_id = intval($user_id);
     $table_class_user = Database::get_main_table(TABLE_MAIN_CLASS_USER);
     $table_course_class = Database::get_main_table(TABLE_MAIN_COURSE_CLASS);
     $courses = ClassManager::get_courses($class_id);
     if (count($courses) != 0) {
         $course_codes = array();
         foreach ($courses as $index => $course) {
             $course_codes[] = $course['course_code'];
             $sql = "SELECT DISTINCT user_id FROM {$table_class_user} t1, {$table_course_class} t2 WHERE t1.class_id=t2.class_id AND course_code = '" . $course['course_code'] . "' AND user_id = {$user_id} AND t2.class_id<>'{$class_id}'";
             $res = Database::query($sql);
             if (Database::num_rows($res) == 0 && CourseManager::get_user_in_course_status($user_id, $course['course_code']) == STUDENT) {
                 CourseManager::unsubscribe_user($user_id, $course['course_code']);
             }
         }
     }
     $sql = "DELETE FROM {$table_class_user} WHERE user_id='" . $user_id . "' AND class_id = '" . $class_id . "'";
     Database::query($sql);
 }
Exemplo n.º 12
0
/**
 * Saves imported data.
 */
function save_data($users_classes)
{
    global $purification_option_for_usernames;
    // Table definitions.
    $user_table = Database::get_main_table(TABLE_MAIN_USER);
    $class_user_table = Database::get_main_table(TABLE_MAIN_CLASS_USER);
    $class_table = Database::get_main_table(TABLE_MAIN_CLASS);
    // Data parsing: purification + conversion (UserName, ClassName) --> (user_is, class_id)
    $csv_data = array();
    foreach ($users_classes as $index => $user_class) {
        $sql1 = "SELECT user_id FROM {$user_table} WHERE username = '******'UserName'], $purification_option_for_usernames)) . "'";
        $res1 = Database::query($sql1);
        $obj1 = Database::fetch_object($res1);
        $sql2 = "SELECT id FROM {$class_table} WHERE name = '" . Database::escape_string(trim($user_class['ClassName'])) . "'";
        $res2 = Database::query($sql2);
        $obj2 = Database::fetch_object($res2);
        if ($obj1 && $obj2) {
            $csv_data[$obj1->user_id][$obj2->id] = 1;
        }
    }
    // Logic for processing the request (data + UI options).
    $db_subscriptions = array();
    foreach ($csv_data as $user_id => $csv_subscriptions) {
        $sql = "SELECT class_id FROM {$class_user_table} cu WHERE cu.user_id = {$user_id}";
        $res = Database::query($sql);
        while ($obj = Database::fetch_object($res)) {
            $db_subscriptions[$obj->class_id] = 1;
        }
        $to_subscribe = array_diff(array_keys($csv_subscriptions), array_keys($db_subscriptions));
        $to_unsubscribe = array_diff(array_keys($db_subscriptions), array_keys($csv_subscriptions));
        // Subscriptions for new classes.
        if ($_POST['subscribe']) {
            foreach ($to_subscribe as $class_id) {
                ClassManager::add_user($user_id, $class_id);
            }
        }
        // Unsubscription from previous classes.
        if ($_POST['unsubscribe']) {
            foreach ($to_unsubscribe as $class_id) {
                ClassManager::unsubscribe_user($user_id, $class_id);
            }
        }
    }
}
 function saveCurrentCart()
 {
     ClassManager::includeClass('customer');
     $customerEntry = Customer::getAuthedInstance();
     $customerID = isset($_SESSION["log"]) ? regGetIdByLogin($_SESSION["log"]) : 0;
     if ($customerEntry instanceof customer) {
         $this->saveToCurrentCustomerCart();
     } else {
         $this->saveToCurrentSessionCart();
     }
 }
Exemplo n.º 14
0
 /**
  * Unsubscribe a user from a class. If the class is also subscribed in a
  * course, the user will be unsubscribed from that course
  * @param int $user_id The user id
  * @param int $class_id The class id
  */
 public static function unsubscribe_user($user_id, $class_id)
 {
     $class_id = intval($class_id);
     $user_id = intval($user_id);
     $em = Database::getManager();
     $table_class_user = Database::get_main_table(TABLE_MAIN_CLASS_USER);
     $courses = ClassManager::get_courses($class_id);
     if (count($courses) != 0) {
         $course_codes = array();
         foreach ($courses as $index => $course) {
             $course_codes[] = $course['course_code'];
             $dql = '
                 SELECT DISTICT cu.userId
                 FROM ChamiloCoreBundle:ClassUser cu, ChamiloCoreBundle:CourseRelClass cc
                 WHERE
                     cu.classId = cc.classId AND
                     cc.courseId = :course AND
                     cu.userId = :user AND 
                     cc.classId != :class
             ';
             $res = $em->createQuery($dql)->setParameters(['course' => $course['id'], 'user' => $user_id, 'class' => $class_id])->getResult();
             if (count($res) === 0 && CourseManager::get_user_in_course_status($user_id, $course['course_code']) == STUDENT) {
                 CourseManager::unsubscribe_user($user_id, $course['course_code']);
             }
         }
     }
     $sql = "DELETE FROM {$table_class_user} WHERE user_id='" . $user_id . "' AND class_id = '" . $class_id . "'";
     Database::query($sql);
 }
	/**
	 * Loads the class with the given class name from the index.
	 *
	 * @param	string	Class Name
	 */
	public static function autoload($className) {
		if (self::$instance == null) {
			self::$instance = new self();
		}
		self::$instance->loadFile($className);
	}
Exemplo n.º 16
0
 protected function readClass()
 {
     $classname = ClassManager::getClass($this->_readStringWithoutTag());
     $count = (int) $this->stream->readuntil(Tags::TagOpenbrace);
     $props = new \SplFixedArray($count);
     for ($i = 0; $i < $count; ++$i) {
         $props[$i] = $this->_readString();
     }
     $this->stream->skip(1);
     $this->classref[] = array($classname, $props);
 }
Exemplo n.º 17
0
*/
/**
 * Code
 */
// Resetting the course id.
$cidReset = true;
// Including some necessary dokeos files.
//require_once '../inc/global.inc.php';
// Setting the section (for the tabs).
$this_section = SECTION_PLATFORM_ADMIN;
// Access restrictions.
api_protect_admin_script();
// Setting breadcrumbs.
$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array('url' => 'class_list.php', 'name' => get_lang('Classes'));
// Setting the name of the tool.
$tool_name = get_lang("AddClasses");
$form = new FormValidator('add_class');
$form->addText('name', get_lang('ClassName'));
$form->addButtonCreate(get_lang('Ok'));
if ($form->validate()) {
    $values = $form->exportValues();
    ClassManager::create_class($values['name']);
    header('Location: class_list.php');
}
// Displaying the header.
Display::display_header($tool_name);
// Displaying the form.
$form->display();
// Displaying the footer.
Display::display_footer();
Exemplo n.º 18
0
$tool_name = get_lang("AddClassesToACourse");
//extra entries in breadcrumb
$interbreadcrumb[] = array("url" => "user.php", "name" => get_lang("ToolUser"));
$interbreadcrumb[] = array("url" => "class.php", "name" => get_lang("Classes"));
Display::display_header($tool_name, "User");
echo Display::page_header($tool_name);
if (isset($_GET['register'])) {
    ClassManager::subscribe_to_course($_GET['class_id'], $_course['sysCode']);
    Display::display_normal_message(get_lang('ClassesSubscribed'));
}
if (isset($_POST['action'])) {
    switch ($_POST['action']) {
        case 'subscribe':
            if (is_array($_POST['class'])) {
                foreach ($_POST['class'] as $index => $class_id) {
                    ClassManager::subscribe_to_course($class_id, $_course['sysCode']);
                }
                Display::display_normal_message(get_lang('ClassesSubscribed'));
            }
            break;
    }
}
/*
 SHOW LIST OF USERS
*/
/**
 *  * Get the number of classes to display on the current page.
 */
function get_number_of_classes()
{
    $class_table = Database::get_main_table(TABLE_MAIN_CLASS);
 /**
  * Replace the method implementation
  *
  * @param string $class_name
  * @param string $method_name
  * @param callable $callable
  */
 public function replace($class_name, $method_name, \Closure $callable)
 {
     ClassManager::getInstance()->register($class_name, $method_name, $callable);
     $this->class_and_methods[] = array($class_name, $method_name);
 }
Exemplo n.º 20
0
/**
 * Save the imported data
 * @param   array   List of users
 * @return  void
 * @uses global variable $inserted_in_course, which returns the list of courses the user was inserted in
 */
function save_data($users)
{
    global $inserted_in_course;
    // Not all scripts declare the $inserted_in_course array (although they should).
    if (!isset($inserted_in_course)) {
        $inserted_in_course = array();
    }
    $send_mail = $_POST['sendMail'] ? 1 : 0;
    if (is_array($users)) {
        foreach ($users as $index => $user) {
            $user = complete_missing_data($user);
            $user['Status'] = api_status_key($user['Status']);
            $user_id = UserManager::create_user($user['FirstName'], $user['LastName'], $user['Status'], $user['Email'], $user['UserName'], $user['Password'], $user['OfficialCode'], $user['language'], $user['PhoneNumber'], '', $user['AuthSource'], null, 1, 0, null, null, $send_mail);
            if (!is_array($user['Courses']) && !empty($user['Courses'])) {
                $user['Courses'] = array($user['Courses']);
            }
            if (is_array($user['Courses'])) {
                foreach ($user['Courses'] as $index => $course) {
                    if (CourseManager::course_exists($course)) {
                        CourseManager::subscribe_user($user_id, $course, $user['Status']);
                        $course_info = CourseManager::get_course_information($course);
                        $inserted_in_course[$course] = $course_info['title'];
                    }
                    if (CourseManager::course_exists($course, true)) {
                        // Also subscribe to virtual courses through check on visual code.
                        $list = CourseManager::get_courses_info_from_visual_code($course);
                        foreach ($list as $vcourse) {
                            if ($vcourse['code'] == $course) {
                                // Ignore, this has already been inserted.
                            } else {
                                CourseManager::subscribe_user($user_id, $vcourse['code'], $user['Status']);
                                $inserted_in_course[$vcourse['code']] = $vcourse['title'];
                            }
                        }
                    }
                }
            }
            if (!empty($user['ClassName'])) {
                $class_id = ClassManager::get_class_id($user['ClassName']);
                ClassManager::add_user($user_id, $class_id);
            }
            // Saving extra fields.
            global $extra_fields;
            // We are sure that the extra field exists.
            foreach ($extra_fields as $extras) {
                if (isset($user[$extras[1]])) {
                    $key = $extras[1];
                    $value = $user[$extras[1]];
                    UserManager::update_extra_field_value($user_id, $key, $value);
                }
            }
        }
    }
}