@@ -251,12 +251,12 @@ discard block |
||
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
254 | - * update user info about certificate |
|
255 | - * @param int $cat_id category id |
|
256 | - * @param int $user_id user id |
|
257 | - * @param string $path_certificate the path name of the certificate |
|
258 | - * @return void |
|
259 | - */ |
|
254 | + * update user info about certificate |
|
255 | + * @param int $cat_id category id |
|
256 | + * @param int $user_id user id |
|
257 | + * @param string $path_certificate the path name of the certificate |
|
258 | + * @return void |
|
259 | + */ |
|
260 | 260 | public function update_user_info_about_certificate( |
261 | 261 | $cat_id, |
262 | 262 | $user_id, |
@@ -359,13 +359,13 @@ discard block |
||
359 | 359 | } |
360 | 360 | |
361 | 361 | /** |
362 | - * Shows the student's certificate (HTML file). If the global setting |
|
363 | - * allow_public_certificates is set to 'false', no certificate can be printed. |
|
364 | - * If the global allow_public_certificates is set to 'true' and the course |
|
365 | - * setting allow_public_certificates is set to 0, no certificate *in this |
|
366 | - * course* can be printed (for anonymous users). Connected users can always |
|
367 | - * print them. |
|
368 | - */ |
|
362 | + * Shows the student's certificate (HTML file). If the global setting |
|
363 | + * allow_public_certificates is set to 'false', no certificate can be printed. |
|
364 | + * If the global allow_public_certificates is set to 'true' and the course |
|
365 | + * setting allow_public_certificates is set to 0, no certificate *in this |
|
366 | + * course* can be printed (for anonymous users). Connected users can always |
|
367 | + * print them. |
|
368 | + */ |
|
369 | 369 | public function show() |
370 | 370 | { |
371 | 371 | // Special rules for anonymous users |
@@ -373,13 +373,13 @@ discard block |
||
373 | 373 | $firstname = $userInfo['firstname']; |
374 | 374 | $lastname = $userInfo['lastname']; |
375 | 375 | |
376 | - if (api_is_western_name_order()) { |
|
377 | - $message = sprintf(get_lang('AttemptingToLoginAs'),$firstname, $lastname, $userId); |
|
378 | - } else { |
|
379 | - $message = sprintf(get_lang('AttemptingToLoginAs'), $lastname, $firstname, $userId); |
|
380 | - } |
|
376 | + if (api_is_western_name_order()) { |
|
377 | + $message = sprintf(get_lang('AttemptingToLoginAs'),$firstname, $lastname, $userId); |
|
378 | + } else { |
|
379 | + $message = sprintf(get_lang('AttemptingToLoginAs'), $lastname, $firstname, $userId); |
|
380 | + } |
|
381 | 381 | |
382 | - if ($userId) { |
|
382 | + if ($userId) { |
|
383 | 383 | |
384 | 384 | // Logout the current user |
385 | 385 | LoginDelete(api_get_user_id()); |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | }*/ |
455 | 455 | |
456 | 456 | if (!in_array($direction, array('ASC','DESC'))) { |
457 | - $direction = 'ASC'; |
|
457 | + $direction = 'ASC'; |
|
458 | 458 | } |
459 | 459 | $column = intval($column); |
460 | 460 | $from = intval($from); |
@@ -465,23 +465,23 @@ discard block |
||
465 | 465 | $sql .= " WHERE u.creator_id = ".api_get_user_id(); |
466 | 466 | } |
467 | 467 | |
468 | - $sql .= " ORDER BY col$column $direction "; |
|
469 | - $sql .= " LIMIT $from,$number_of_items"; |
|
468 | + $sql .= " ORDER BY col$column $direction "; |
|
469 | + $sql .= " LIMIT $from,$number_of_items"; |
|
470 | 470 | |
471 | - $res = Database::query($sql); |
|
471 | + $res = Database::query($sql); |
|
472 | 472 | |
473 | - $users = array (); |
|
473 | + $users = array (); |
|
474 | 474 | $t = time(); |
475 | - while ($user = Database::fetch_row($res)) { |
|
476 | - $userPicture = UserManager::getUserPicture($user[0], USER_IMAGE_SIZE_SMALL); |
|
477 | - $photo = '<img src="'.$userPicture.'" width="22" height="22" alt="'.api_get_person_name($user[2], $user[3]).'" title="'.api_get_person_name($user[2], $user[3]).'" />'; |
|
475 | + while ($user = Database::fetch_row($res)) { |
|
476 | + $userPicture = UserManager::getUserPicture($user[0], USER_IMAGE_SIZE_SMALL); |
|
477 | + $photo = '<img src="'.$userPicture.'" width="22" height="22" alt="'.api_get_person_name($user[2], $user[3]).'" title="'.api_get_person_name($user[2], $user[3]).'" />'; |
|
478 | 478 | |
479 | 479 | if ($user[7] == 1 && !empty($user[10])) { |
480 | 480 | // check expiration date |
481 | 481 | $expiration_time = convert_sql_date($user[10]); |
482 | 482 | // if expiration date is passed, store a special value for active field |
483 | 483 | if ($expiration_time < $t) { |
484 | - $user[7] = '-1'; |
|
484 | + $user[7] = '-1'; |
|
485 | 485 | } |
486 | 486 | } |
487 | 487 | |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | */ |
512 | 512 | function email_filter($email) |
513 | 513 | { |
514 | - return Display :: encrypted_mailto_link($email, $email); |
|
514 | + return Display :: encrypted_mailto_link($email, $email); |
|
515 | 515 | } |
516 | 516 | |
517 | 517 | /** |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | */ |
522 | 522 | function user_filter($name, $params, $row) |
523 | 523 | { |
524 | - return '<a href="'.api_get_path(WEB_PATH).'whoisonline.php?origin=user_list&id='.$row[0].'">'.$name.'</a>'; |
|
524 | + return '<a href="'.api_get_path(WEB_PATH).'whoisonline.php?origin=user_list&id='.$row[0].'">'.$name.'</a>'; |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | /** |
@@ -533,32 +533,32 @@ discard block |
||
533 | 533 | */ |
534 | 534 | function modify_filter($user_id, $url_params, $row) |
535 | 535 | { |
536 | - global $charset, $_admins_list; |
|
536 | + global $charset, $_admins_list; |
|
537 | 537 | $is_admin = in_array($user_id, $_admins_list); |
538 | 538 | $statusname = api_get_status_langvars(); |
539 | 539 | $user_is_anonymous = false; |
540 | 540 | $current_user_status_label = $row['7']; |
541 | 541 | |
542 | - if ($current_user_status_label == $statusname[ANONYMOUS]) { |
|
543 | - $user_is_anonymous =true; |
|
544 | - } |
|
545 | - $result = ''; |
|
546 | - if (!$user_is_anonymous) { |
|
547 | - $icon = Display::return_icon('course.png', get_lang('Courses'), array('onmouseout' => 'clear_course_list (\'div_'.$user_id.'\')')); |
|
548 | - $result .= '<a href="javascript:void(0)" onclick="load_course_list(\'div_'.$user_id.'\','.$user_id.')" > |
|
542 | + if ($current_user_status_label == $statusname[ANONYMOUS]) { |
|
543 | + $user_is_anonymous =true; |
|
544 | + } |
|
545 | + $result = ''; |
|
546 | + if (!$user_is_anonymous) { |
|
547 | + $icon = Display::return_icon('course.png', get_lang('Courses'), array('onmouseout' => 'clear_course_list (\'div_'.$user_id.'\')')); |
|
548 | + $result .= '<a href="javascript:void(0)" onclick="load_course_list(\'div_'.$user_id.'\','.$user_id.')" > |
|
549 | 549 | '.$icon.' |
550 | 550 | <div class="blackboard_hide" id="div_'.$user_id.'"> </div> |
551 | 551 | </a>'; |
552 | 552 | |
553 | 553 | $icon = Display::return_icon('session.png', get_lang('Sessions'), array('onmouseout' => 'clear_session_list (\'div_s_'.$user_id.'\')')); |
554 | - $result .= '<a href="javascript:void(0)" onclick="load_session_list(\'div_s_'.$user_id.'\','.$user_id.')" > |
|
554 | + $result .= '<a href="javascript:void(0)" onclick="load_session_list(\'div_s_'.$user_id.'\','.$user_id.')" > |
|
555 | 555 | '.$icon.' |
556 | 556 | <div class="blackboard_hide" id="div_s_'.$user_id.'"> </div> |
557 | 557 | </a>'; |
558 | - } else { |
|
559 | - $result .= Display::return_icon('course_na.png',get_lang('Courses')).' '; |
|
560 | - $result .= Display::return_icon('course_na.png',get_lang('Sessions')).' '; |
|
561 | - } |
|
558 | + } else { |
|
559 | + $result .= Display::return_icon('course_na.png',get_lang('Courses')).' '; |
|
560 | + $result .= Display::return_icon('course_na.png',get_lang('Sessions')).' '; |
|
561 | + } |
|
562 | 562 | |
563 | 563 | if (api_is_platform_admin()) { |
564 | 564 | if (!$user_is_anonymous) { |
@@ -607,14 +607,14 @@ discard block |
||
607 | 607 | ); |
608 | 608 | } |
609 | 609 | |
610 | - if ($is_admin) { |
|
611 | - $result .= Display::return_icon('admin_star.png', get_lang('IsAdministrator'),array('width'=> ICON_SIZE_SMALL, 'heigth'=> ICON_SIZE_SMALL)); |
|
612 | - } else { |
|
613 | - $result .= Display::return_icon('admin_star_na.png', get_lang('IsNotAdministrator')); |
|
614 | - } |
|
610 | + if ($is_admin) { |
|
611 | + $result .= Display::return_icon('admin_star.png', get_lang('IsAdministrator'),array('width'=> ICON_SIZE_SMALL, 'heigth'=> ICON_SIZE_SMALL)); |
|
612 | + } else { |
|
613 | + $result .= Display::return_icon('admin_star_na.png', get_lang('IsNotAdministrator')); |
|
614 | + } |
|
615 | 615 | |
616 | - // actions for assigning sessions, courses or users |
|
617 | - if (!api_is_session_admin()) { |
|
616 | + // actions for assigning sessions, courses or users |
|
617 | + if (!api_is_session_admin()) { |
|
618 | 618 | if ($current_user_status_label == $statusname[SESSIONADMIN]) { |
619 | 619 | $result .= Display::url( |
620 | 620 | Display::return_icon('view_more_stats.gif', get_lang('AssignSessions')), |
@@ -644,7 +644,7 @@ discard block |
||
644 | 644 | ); |
645 | 645 | } |
646 | 646 | } |
647 | - } |
|
647 | + } |
|
648 | 648 | |
649 | 649 | if (api_is_platform_admin()) { |
650 | 650 | $result .= ' <a data-title="'.get_lang('FreeBusyCalendar').'" href="'.api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?a=get_user_agenda&user_id='.$user_id.'&modal_size=lg" class="agenda_opener ajax">'. |
@@ -662,7 +662,7 @@ discard block |
||
662 | 662 | } |
663 | 663 | } |
664 | 664 | } |
665 | - return $result; |
|
665 | + return $result; |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | /** |
@@ -694,11 +694,11 @@ discard block |
||
694 | 694 | if ($action === 'edit') { |
695 | 695 | $result = Display::return_icon($image.'.png', get_lang('AccountExpired'), array(), 16); |
696 | 696 | } elseif ($row['0'] <> $_user['user_id']) { |
697 | - // you cannot lock yourself out otherwise you could disable all the accounts including your own => everybody is locked out and nobody can change it anymore. |
|
698 | - $result = Display::return_icon($image.'.png', get_lang(ucfirst($action)), array('onclick'=>'active_user(this);', 'id'=>'img_'.$row['0']), 16).'</a>'; |
|
699 | - } |
|
697 | + // you cannot lock yourself out otherwise you could disable all the accounts including your own => everybody is locked out and nobody can change it anymore. |
|
698 | + $result = Display::return_icon($image.'.png', get_lang(ucfirst($action)), array('onclick'=>'active_user(this);', 'id'=>'img_'.$row['0']), 16).'</a>'; |
|
699 | + } |
|
700 | 700 | |
701 | - return $result; |
|
701 | + return $result; |
|
702 | 702 | } |
703 | 703 | |
704 | 704 | /** |
@@ -711,8 +711,8 @@ discard block |
||
711 | 711 | * @author Patrick Cool <[email protected]>, Ghent University, Belgium |
712 | 712 | */ |
713 | 713 | function status_filter($status) { |
714 | - $statusname = api_get_status_langvars(); |
|
715 | - return $statusname[$status]; |
|
714 | + $statusname = api_get_status_langvars(); |
|
715 | + return $statusname[$status]; |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | if (isset($_GET['keyword']) || isset($_GET['keyword_firstname'])) { |
@@ -728,8 +728,8 @@ discard block |
||
728 | 728 | |
729 | 729 | if (!empty($action)) { |
730 | 730 | $check = Security::check_token('get'); |
731 | - if ($check) { |
|
732 | - switch ($action) { |
|
731 | + if ($check) { |
|
732 | + switch ($action) { |
|
733 | 733 | case 'add_user_to_my_url': |
734 | 734 | $user_id = $_REQUEST["user_id"]; |
735 | 735 | $result = UrlManager::add_user_to_url($user_id, $current_access_url_id); |
@@ -739,45 +739,45 @@ discard block |
||
739 | 739 | $message = Display::return_message($message, 'confirmation'); |
740 | 740 | } |
741 | 741 | break; |
742 | - case 'delete_user': |
|
743 | - if (api_is_platform_admin()) { |
|
742 | + case 'delete_user': |
|
743 | + if (api_is_platform_admin()) { |
|
744 | 744 | $user_to_delete = $_GET['user_id']; |
745 | 745 | $current_user_id = api_get_user_id(); |
746 | 746 | |
747 | - if ($deleteUserAvailable && api_global_admin_can_edit_admin($_GET['user_id'])) { |
|
748 | - if ($user_to_delete != $current_user_id && UserManager :: delete_user($_GET['user_id'])) { |
|
749 | - $message = Display :: return_message(get_lang('UserDeleted'), 'confirmation'); |
|
750 | - } else { |
|
751 | - $message = Display :: return_message(get_lang('CannotDeleteUserBecauseOwnsCourse'), 'error'); |
|
752 | - } |
|
753 | - } else { |
|
754 | - $message = Display :: return_message(get_lang('CannotDeleteUser'),'error'); |
|
755 | - } |
|
756 | - } |
|
757 | - break; |
|
747 | + if ($deleteUserAvailable && api_global_admin_can_edit_admin($_GET['user_id'])) { |
|
748 | + if ($user_to_delete != $current_user_id && UserManager :: delete_user($_GET['user_id'])) { |
|
749 | + $message = Display :: return_message(get_lang('UserDeleted'), 'confirmation'); |
|
750 | + } else { |
|
751 | + $message = Display :: return_message(get_lang('CannotDeleteUserBecauseOwnsCourse'), 'error'); |
|
752 | + } |
|
753 | + } else { |
|
754 | + $message = Display :: return_message(get_lang('CannotDeleteUser'),'error'); |
|
755 | + } |
|
756 | + } |
|
757 | + break; |
|
758 | 758 | case 'delete': |
759 | - if (api_is_platform_admin()) { |
|
760 | - $number_of_selected_users = count($_POST['id']); |
|
761 | - $number_of_deleted_users = 0; |
|
762 | - if (is_array($_POST['id'])) { |
|
763 | - foreach ($_POST['id'] as $index => $user_id) { |
|
764 | - if ($user_id != $_user['user_id']) { |
|
765 | - if (UserManager::delete_user($user_id)) { |
|
766 | - $number_of_deleted_users++; |
|
767 | - } |
|
768 | - } |
|
769 | - } |
|
770 | - } |
|
771 | - if ($number_of_selected_users == $number_of_deleted_users) { |
|
759 | + if (api_is_platform_admin()) { |
|
760 | + $number_of_selected_users = count($_POST['id']); |
|
761 | + $number_of_deleted_users = 0; |
|
762 | + if (is_array($_POST['id'])) { |
|
763 | + foreach ($_POST['id'] as $index => $user_id) { |
|
764 | + if ($user_id != $_user['user_id']) { |
|
765 | + if (UserManager::delete_user($user_id)) { |
|
766 | + $number_of_deleted_users++; |
|
767 | + } |
|
768 | + } |
|
769 | + } |
|
770 | + } |
|
771 | + if ($number_of_selected_users == $number_of_deleted_users) { |
|
772 | 772 | $message = Display :: return_message(get_lang('SelectedUsersDeleted'), 'confirmation'); |
773 | - } else { |
|
773 | + } else { |
|
774 | 774 | $message = Display :: return_message(get_lang('SomeUsersNotDeleted'), 'error'); |
775 | - } |
|
776 | - } |
|
777 | - break; |
|
778 | - } |
|
779 | - Security::clear_token(); |
|
780 | - } |
|
775 | + } |
|
776 | + } |
|
777 | + break; |
|
778 | + } |
|
779 | + Security::clear_token(); |
|
780 | + } |
|
781 | 781 | } |
782 | 782 | |
783 | 783 | // Create a search-box |
@@ -794,15 +794,15 @@ discard block |
||
794 | 794 | $actionsCenter = ''; |
795 | 795 | $actionsRight = ''; |
796 | 796 | if (api_is_platform_admin()) { |
797 | - $actionsRight .= '<a class="pull-right" href="'.api_get_path(WEB_CODE_PATH).'admin/user_add.php">'. |
|
798 | - Display::return_icon('new_user.png',get_lang('AddUsers'),'',ICON_SIZE_MEDIUM).'</a>'; |
|
797 | + $actionsRight .= '<a class="pull-right" href="'.api_get_path(WEB_CODE_PATH).'admin/user_add.php">'. |
|
798 | + Display::return_icon('new_user.png',get_lang('AddUsers'),'',ICON_SIZE_MEDIUM).'</a>'; |
|
799 | 799 | } |
800 | 800 | |
801 | 801 | $actionsLeft .= $form->returnForm(); |
802 | 802 | $actionsCenter .= $searchAdvanced; |
803 | 803 | |
804 | 804 | if (isset($_GET['keyword'])) { |
805 | - $parameters = array('keyword' => Security::remove_XSS($_GET['keyword'])); |
|
805 | + $parameters = array('keyword' => Security::remove_XSS($_GET['keyword'])); |
|
806 | 806 | } elseif (isset ($_GET['keyword_firstname'])) { |
807 | 807 | $parameters['keyword_firstname'] = Security::remove_XSS($_GET['keyword_firstname']); |
808 | 808 | $parameters['keyword_lastname'] = Security::remove_XSS($_GET['keyword_lastname']); |
@@ -878,11 +878,11 @@ discard block |
||
878 | 878 | $table->set_header(2, get_lang('OfficialCode')); |
879 | 879 | |
880 | 880 | if (api_is_western_name_order()) { |
881 | - $table->set_header(3, get_lang('FirstName')); |
|
882 | - $table->set_header(4, get_lang('LastName')); |
|
881 | + $table->set_header(3, get_lang('FirstName')); |
|
882 | + $table->set_header(4, get_lang('LastName')); |
|
883 | 883 | } else { |
884 | - $table->set_header(3, get_lang('LastName')); |
|
885 | - $table->set_header(4, get_lang('FirstName')); |
|
884 | + $table->set_header(3, get_lang('LastName')); |
|
885 | + $table->set_header(4, get_lang('FirstName')); |
|
886 | 886 | } |
887 | 887 | $table->set_header(5, get_lang('LoginName')); |
888 | 888 | $table->set_header(6, get_lang('Email')); |
@@ -1267,13 +1267,13 @@ discard block |
||
1267 | 1267 | } |
1268 | 1268 | |
1269 | 1269 | /** |
1270 | - * Get the users by ID |
|
1271 | - * @param array $ids student ids |
|
1272 | - * @param string $active |
|
1273 | - * @param string $order |
|
1274 | - * @param string $limit |
|
1275 | - * @return array $result student information |
|
1276 | - */ |
|
1270 | + * Get the users by ID |
|
1271 | + * @param array $ids student ids |
|
1272 | + * @param string $active |
|
1273 | + * @param string $order |
|
1274 | + * @param string $limit |
|
1275 | + * @return array $result student information |
|
1276 | + */ |
|
1277 | 1277 | public static function get_user_list_by_ids($ids = array(), $active = null, $order = null, $limit = null) |
1278 | 1278 | { |
1279 | 1279 | if (empty($ids)) { |
@@ -2314,7 +2314,7 @@ discard block |
||
2314 | 2314 | * |
2315 | 2315 | * @return array with extra data info of a user i.e array('field_variable'=>'value'); |
2316 | 2316 | */ |
2317 | - public static function get_extra_user_data_by_value($variable, $value, $all_visibility = true) |
|
2317 | + public static function get_extra_user_data_by_value($variable, $value, $all_visibility = true) |
|
2318 | 2318 | { |
2319 | 2319 | $extraFieldValue = new ExtraFieldValue('user'); |
2320 | 2320 | $extraField = new ExtraField('user'); |
@@ -3409,12 +3409,12 @@ discard block |
||
3409 | 3409 | if ($tag_id == 0) { |
3410 | 3410 | //the tag doesn't exist |
3411 | 3411 | $sql = "INSERT INTO $table_user_tag (tag, field_id,count) VALUES ('$tag','$field_id', count + 1)"; |
3412 | - Database::query($sql); |
|
3412 | + Database::query($sql); |
|
3413 | 3413 | $last_insert_id = Database::insert_id(); |
3414 | 3414 | } else { |
3415 | 3415 | //the tag exists we update it |
3416 | 3416 | $sql = "UPDATE $table_user_tag SET count = count + 1 WHERE id = $tag_id"; |
3417 | - Database::query($sql); |
|
3417 | + Database::query($sql); |
|
3418 | 3418 | $last_insert_id = $tag_id; |
3419 | 3419 | } |
3420 | 3420 | |
@@ -3610,9 +3610,9 @@ discard block |
||
3610 | 3610 | } |
3611 | 3611 | |
3612 | 3612 | /** |
3613 | - * Get extra filtrable user fields (only type select) |
|
3614 | - * @return array |
|
3615 | - */ |
|
3613 | + * Get extra filtrable user fields (only type select) |
|
3614 | + * @return array |
|
3615 | + */ |
|
3616 | 3616 | public static function get_extra_filtrable_fields() |
3617 | 3617 | { |
3618 | 3618 | $extraFieldList = UserManager::get_extra_fields(); |
@@ -3637,9 +3637,9 @@ discard block |
||
3637 | 3637 | } |
3638 | 3638 | |
3639 | 3639 | /** |
3640 | - * Get extra where clauses for finding users based on extra filtrable user fields (type select) |
|
3641 | - * @return string With AND clauses based on user's ID which have the values to search in extra user fields |
|
3642 | - */ |
|
3640 | + * Get extra where clauses for finding users based on extra filtrable user fields (type select) |
|
3641 | + * @return string With AND clauses based on user's ID which have the values to search in extra user fields |
|
3642 | + */ |
|
3643 | 3643 | public static function get_search_form_where_extra_fields() |
3644 | 3644 | { |
3645 | 3645 | $useExtraFields = false; |
@@ -3958,23 +3958,23 @@ discard block |
||
3958 | 3958 | } |
3959 | 3959 | |
3960 | 3960 | /** |
3961 | - * Get users followed by human resource manager |
|
3962 | - * @param int $userId |
|
3963 | - * @param int $userStatus Filter users by status (STUDENT, COURSEMANAGER, etc) |
|
3964 | - * @param bool $getOnlyUserId |
|
3965 | - * @param bool $getSql |
|
3966 | - * @param bool $getCount |
|
3967 | - * @param int $from |
|
3968 | - * @param int $numberItems |
|
3969 | - * @param int $column |
|
3970 | - * @param string $direction |
|
3971 | - * @param int $active |
|
3972 | - * @param string $lastConnectionDate |
|
3973 | - * @param int $status the function is called by who? COURSEMANAGER, DRH? |
|
3974 | - * @param string $keyword |
|
3961 | + * Get users followed by human resource manager |
|
3962 | + * @param int $userId |
|
3963 | + * @param int $userStatus Filter users by status (STUDENT, COURSEMANAGER, etc) |
|
3964 | + * @param bool $getOnlyUserId |
|
3965 | + * @param bool $getSql |
|
3966 | + * @param bool $getCount |
|
3967 | + * @param int $from |
|
3968 | + * @param int $numberItems |
|
3969 | + * @param int $column |
|
3970 | + * @param string $direction |
|
3971 | + * @param int $active |
|
3972 | + * @param string $lastConnectionDate |
|
3973 | + * @param int $status the function is called by who? COURSEMANAGER, DRH? |
|
3974 | + * @param string $keyword |
|
3975 | 3975 | * |
3976 | - * @return array user list |
|
3977 | - */ |
|
3976 | + * @return array user list |
|
3977 | + */ |
|
3978 | 3978 | public static function getUsersFollowedByUser( |
3979 | 3979 | $userId, |
3980 | 3980 | $userStatus = null, |
@@ -83,809 +83,809 @@ discard block |
||
83 | 83 | * @access public |
84 | 84 | */ |
85 | 85 | class nusoap_base { |
86 | - /** |
|
87 | - * Identification for HTTP headers. |
|
88 | - * |
|
89 | - * @var string |
|
90 | - * @access private |
|
91 | - */ |
|
92 | - var $title = 'NuSOAP'; |
|
93 | - /** |
|
94 | - * Version for HTTP headers. |
|
95 | - * |
|
96 | - * @var string |
|
97 | - * @access private |
|
98 | - */ |
|
99 | - var $version = '0.9.5'; |
|
100 | - /** |
|
101 | - * CVS revision for HTTP headers. |
|
102 | - * |
|
103 | - * @var string |
|
104 | - * @access private |
|
105 | - */ |
|
106 | - var $revision = '$Revision: 1.56 $'; |
|
86 | + /** |
|
87 | + * Identification for HTTP headers. |
|
88 | + * |
|
89 | + * @var string |
|
90 | + * @access private |
|
91 | + */ |
|
92 | + var $title = 'NuSOAP'; |
|
93 | + /** |
|
94 | + * Version for HTTP headers. |
|
95 | + * |
|
96 | + * @var string |
|
97 | + * @access private |
|
98 | + */ |
|
99 | + var $version = '0.9.5'; |
|
100 | + /** |
|
101 | + * CVS revision for HTTP headers. |
|
102 | + * |
|
103 | + * @var string |
|
104 | + * @access private |
|
105 | + */ |
|
106 | + var $revision = '$Revision: 1.56 $'; |
|
107 | 107 | /** |
108 | 108 | * Current error string (manipulated by getError/setError) |
109 | - * |
|
110 | - * @var string |
|
111 | - * @access private |
|
112 | - */ |
|
113 | - var $error_str = ''; |
|
109 | + * |
|
110 | + * @var string |
|
111 | + * @access private |
|
112 | + */ |
|
113 | + var $error_str = ''; |
|
114 | 114 | /** |
115 | 115 | * Current debug string (manipulated by debug/appendDebug/clearDebug/getDebug/getDebugAsXMLComment) |
116 | - * |
|
117 | - * @var string |
|
118 | - * @access private |
|
119 | - */ |
|
116 | + * |
|
117 | + * @var string |
|
118 | + * @access private |
|
119 | + */ |
|
120 | 120 | var $debug_str = ''; |
121 | 121 | /** |
122 | - * toggles automatic encoding of special characters as entities |
|
123 | - * (should always be true, I think) |
|
124 | - * |
|
125 | - * @var boolean |
|
126 | - * @access private |
|
127 | - */ |
|
128 | - var $charencoding = true; |
|
129 | - /** |
|
130 | - * the debug level for this instance |
|
131 | - * |
|
132 | - * @var integer |
|
133 | - * @access private |
|
134 | - */ |
|
135 | - var $debugLevel; |
|
136 | - |
|
137 | - /** |
|
138 | - * set schema version |
|
139 | - * |
|
140 | - * @var string |
|
141 | - * @access public |
|
142 | - */ |
|
143 | - var $XMLSchemaVersion = 'http://www.w3.org/2001/XMLSchema'; |
|
144 | - |
|
145 | - /** |
|
146 | - * charset encoding for outgoing messages |
|
147 | - * |
|
148 | - * @var string |
|
149 | - * @access public |
|
150 | - */ |
|
122 | + * toggles automatic encoding of special characters as entities |
|
123 | + * (should always be true, I think) |
|
124 | + * |
|
125 | + * @var boolean |
|
126 | + * @access private |
|
127 | + */ |
|
128 | + var $charencoding = true; |
|
129 | + /** |
|
130 | + * the debug level for this instance |
|
131 | + * |
|
132 | + * @var integer |
|
133 | + * @access private |
|
134 | + */ |
|
135 | + var $debugLevel; |
|
136 | + |
|
137 | + /** |
|
138 | + * set schema version |
|
139 | + * |
|
140 | + * @var string |
|
141 | + * @access public |
|
142 | + */ |
|
143 | + var $XMLSchemaVersion = 'http://www.w3.org/2001/XMLSchema'; |
|
144 | + |
|
145 | + /** |
|
146 | + * charset encoding for outgoing messages |
|
147 | + * |
|
148 | + * @var string |
|
149 | + * @access public |
|
150 | + */ |
|
151 | 151 | var $soap_defencoding = 'ISO-8859-1'; |
152 | - //var $soap_defencoding = 'UTF-8'; |
|
153 | - |
|
154 | - /** |
|
155 | - * namespaces in an array of prefix => uri |
|
156 | - * |
|
157 | - * this is "seeded" by a set of constants, but it may be altered by code |
|
158 | - * |
|
159 | - * @var array |
|
160 | - * @access public |
|
161 | - */ |
|
162 | - var $namespaces = array( |
|
163 | - 'SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/', |
|
164 | - 'xsd' => 'http://www.w3.org/2001/XMLSchema', |
|
165 | - 'xsi' => 'http://www.w3.org/2001/XMLSchema-instance', |
|
166 | - 'SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/' |
|
167 | - ); |
|
168 | - |
|
169 | - /** |
|
170 | - * namespaces used in the current context, e.g. during serialization |
|
171 | - * |
|
172 | - * @var array |
|
173 | - * @access private |
|
174 | - */ |
|
175 | - var $usedNamespaces = array(); |
|
176 | - |
|
177 | - /** |
|
178 | - * XML Schema types in an array of uri => (array of xml type => php type) |
|
179 | - * is this legacy yet? |
|
180 | - * no, this is used by the nusoap_xmlschema class to verify type => namespace mappings. |
|
181 | - * @var array |
|
182 | - * @access public |
|
183 | - */ |
|
184 | - var $typemap = array( |
|
185 | - 'http://www.w3.org/2001/XMLSchema' => array( |
|
186 | - 'string'=>'string','boolean'=>'boolean','float'=>'double','double'=>'double','decimal'=>'double', |
|
187 | - 'duration'=>'','dateTime'=>'string','time'=>'string','date'=>'string','gYearMonth'=>'', |
|
188 | - 'gYear'=>'','gMonthDay'=>'','gDay'=>'','gMonth'=>'','hexBinary'=>'string','base64Binary'=>'string', |
|
189 | - // abstract "any" types |
|
190 | - 'anyType'=>'string','anySimpleType'=>'string', |
|
191 | - // derived datatypes |
|
192 | - 'normalizedString'=>'string','token'=>'string','language'=>'','NMTOKEN'=>'','NMTOKENS'=>'','Name'=>'','NCName'=>'','ID'=>'', |
|
193 | - 'IDREF'=>'','IDREFS'=>'','ENTITY'=>'','ENTITIES'=>'','integer'=>'integer','nonPositiveInteger'=>'integer', |
|
194 | - 'negativeInteger'=>'integer','long'=>'integer','int'=>'integer','short'=>'integer','byte'=>'integer','nonNegativeInteger'=>'integer', |
|
195 | - 'unsignedLong'=>'','unsignedInt'=>'','unsignedShort'=>'','unsignedByte'=>'','positiveInteger'=>''), |
|
196 | - 'http://www.w3.org/2000/10/XMLSchema' => array( |
|
197 | - 'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double', |
|
198 | - 'float'=>'double','dateTime'=>'string', |
|
199 | - 'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'), |
|
200 | - 'http://www.w3.org/1999/XMLSchema' => array( |
|
201 | - 'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double', |
|
202 | - 'float'=>'double','dateTime'=>'string', |
|
203 | - 'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'), |
|
204 | - 'http://soapinterop.org/xsd' => array('SOAPStruct'=>'struct'), |
|
205 | - 'http://schemas.xmlsoap.org/soap/encoding/' => array('base64'=>'string','array'=>'array','Array'=>'array'), |
|
152 | + //var $soap_defencoding = 'UTF-8'; |
|
153 | + |
|
154 | + /** |
|
155 | + * namespaces in an array of prefix => uri |
|
156 | + * |
|
157 | + * this is "seeded" by a set of constants, but it may be altered by code |
|
158 | + * |
|
159 | + * @var array |
|
160 | + * @access public |
|
161 | + */ |
|
162 | + var $namespaces = array( |
|
163 | + 'SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/', |
|
164 | + 'xsd' => 'http://www.w3.org/2001/XMLSchema', |
|
165 | + 'xsi' => 'http://www.w3.org/2001/XMLSchema-instance', |
|
166 | + 'SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/' |
|
167 | + ); |
|
168 | + |
|
169 | + /** |
|
170 | + * namespaces used in the current context, e.g. during serialization |
|
171 | + * |
|
172 | + * @var array |
|
173 | + * @access private |
|
174 | + */ |
|
175 | + var $usedNamespaces = array(); |
|
176 | + |
|
177 | + /** |
|
178 | + * XML Schema types in an array of uri => (array of xml type => php type) |
|
179 | + * is this legacy yet? |
|
180 | + * no, this is used by the nusoap_xmlschema class to verify type => namespace mappings. |
|
181 | + * @var array |
|
182 | + * @access public |
|
183 | + */ |
|
184 | + var $typemap = array( |
|
185 | + 'http://www.w3.org/2001/XMLSchema' => array( |
|
186 | + 'string'=>'string','boolean'=>'boolean','float'=>'double','double'=>'double','decimal'=>'double', |
|
187 | + 'duration'=>'','dateTime'=>'string','time'=>'string','date'=>'string','gYearMonth'=>'', |
|
188 | + 'gYear'=>'','gMonthDay'=>'','gDay'=>'','gMonth'=>'','hexBinary'=>'string','base64Binary'=>'string', |
|
189 | + // abstract "any" types |
|
190 | + 'anyType'=>'string','anySimpleType'=>'string', |
|
191 | + // derived datatypes |
|
192 | + 'normalizedString'=>'string','token'=>'string','language'=>'','NMTOKEN'=>'','NMTOKENS'=>'','Name'=>'','NCName'=>'','ID'=>'', |
|
193 | + 'IDREF'=>'','IDREFS'=>'','ENTITY'=>'','ENTITIES'=>'','integer'=>'integer','nonPositiveInteger'=>'integer', |
|
194 | + 'negativeInteger'=>'integer','long'=>'integer','int'=>'integer','short'=>'integer','byte'=>'integer','nonNegativeInteger'=>'integer', |
|
195 | + 'unsignedLong'=>'','unsignedInt'=>'','unsignedShort'=>'','unsignedByte'=>'','positiveInteger'=>''), |
|
196 | + 'http://www.w3.org/2000/10/XMLSchema' => array( |
|
197 | + 'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double', |
|
198 | + 'float'=>'double','dateTime'=>'string', |
|
199 | + 'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'), |
|
200 | + 'http://www.w3.org/1999/XMLSchema' => array( |
|
201 | + 'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double', |
|
202 | + 'float'=>'double','dateTime'=>'string', |
|
203 | + 'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'), |
|
204 | + 'http://soapinterop.org/xsd' => array('SOAPStruct'=>'struct'), |
|
205 | + 'http://schemas.xmlsoap.org/soap/encoding/' => array('base64'=>'string','array'=>'array','Array'=>'array'), |
|
206 | 206 | 'http://xml.apache.org/xml-soap' => array('Map') |
207 | - ); |
|
208 | - |
|
209 | - /** |
|
210 | - * XML entities to convert |
|
211 | - * |
|
212 | - * @var array |
|
213 | - * @access public |
|
214 | - * @deprecated |
|
215 | - * @see expandEntities |
|
216 | - */ |
|
217 | - var $xmlEntities = array('quot' => '"','amp' => '&', |
|
218 | - 'lt' => '<','gt' => '>','apos' => "'"); |
|
219 | - |
|
220 | - /** |
|
221 | - * constructor |
|
222 | - * |
|
223 | - * @access public |
|
224 | - */ |
|
225 | - function __construct() { |
|
226 | - $this->debugLevel = $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel']; |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * gets the global debug level, which applies to future instances |
|
231 | - * |
|
232 | - * @return integer Debug level 0-9, where 0 turns off |
|
233 | - * @access public |
|
234 | - */ |
|
235 | - function getGlobalDebugLevel() { |
|
236 | - return $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel']; |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * sets the global debug level, which applies to future instances |
|
241 | - * |
|
242 | - * @param int $level Debug level 0-9, where 0 turns off |
|
243 | - * @access public |
|
244 | - */ |
|
245 | - function setGlobalDebugLevel($level) { |
|
246 | - $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = $level; |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * gets the debug level for this instance |
|
251 | - * |
|
252 | - * @return int Debug level 0-9, where 0 turns off |
|
253 | - * @access public |
|
254 | - */ |
|
255 | - function getDebugLevel() { |
|
256 | - return $this->debugLevel; |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * sets the debug level for this instance |
|
261 | - * |
|
262 | - * @param int $level Debug level 0-9, where 0 turns off |
|
263 | - * @access public |
|
264 | - */ |
|
265 | - function setDebugLevel($level) { |
|
266 | - $this->debugLevel = $level; |
|
267 | - } |
|
268 | - |
|
269 | - /** |
|
270 | - * adds debug data to the instance debug string with formatting |
|
271 | - * |
|
272 | - * @param string $string debug data |
|
273 | - * @access private |
|
274 | - */ |
|
275 | - function debug($string){ |
|
276 | - if ($this->debugLevel > 0) { |
|
277 | - $this->appendDebug($this->getmicrotime().' '.get_class($this).": $string\n"); |
|
278 | - } |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * adds debug data to the instance debug string without formatting |
|
283 | - * |
|
284 | - * @param string $string debug data |
|
285 | - * @access public |
|
286 | - */ |
|
287 | - function appendDebug($string){ |
|
288 | - if ($this->debugLevel > 0) { |
|
289 | - // it would be nice to use a memory stream here to use |
|
290 | - // memory more efficiently |
|
291 | - $this->debug_str .= $string; |
|
292 | - } |
|
293 | - } |
|
294 | - |
|
295 | - /** |
|
296 | - * clears the current debug data for this instance |
|
297 | - * |
|
298 | - * @access public |
|
299 | - */ |
|
300 | - function clearDebug() { |
|
301 | - // it would be nice to use a memory stream here to use |
|
302 | - // memory more efficiently |
|
303 | - $this->debug_str = ''; |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * gets the current debug data for this instance |
|
308 | - * |
|
309 | - * @return debug data |
|
310 | - * @access public |
|
311 | - */ |
|
312 | - function &getDebug() { |
|
313 | - // it would be nice to use a memory stream here to use |
|
314 | - // memory more efficiently |
|
315 | - return $this->debug_str; |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * gets the current debug data for this instance as an XML comment |
|
320 | - * this may change the contents of the debug data |
|
321 | - * |
|
322 | - * @return debug data as an XML comment |
|
323 | - * @access public |
|
324 | - */ |
|
325 | - function &getDebugAsXMLComment() { |
|
326 | - // it would be nice to use a memory stream here to use |
|
327 | - // memory more efficiently |
|
328 | - while (strpos($this->debug_str, '--')) { |
|
329 | - $this->debug_str = str_replace('--', '- -', $this->debug_str); |
|
330 | - } |
|
331 | - $ret = "<!--\n" . $this->debug_str . "\n-->"; |
|
332 | - return $ret; |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * expands entities, e.g. changes '<' to '<'. |
|
337 | - * |
|
338 | - * @param string $val The string in which to expand entities. |
|
339 | - * @access private |
|
340 | - */ |
|
341 | - function expandEntities($val) { |
|
342 | - if ($this->charencoding) { |
|
343 | - $val = str_replace('&', '&', $val); |
|
344 | - $val = str_replace("'", ''', $val); |
|
345 | - $val = str_replace('"', '"', $val); |
|
346 | - $val = str_replace('<', '<', $val); |
|
347 | - $val = str_replace('>', '>', $val); |
|
348 | - } |
|
349 | - return $val; |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * returns error string if present |
|
354 | - * |
|
355 | - * @return mixed error string or false |
|
356 | - * @access public |
|
357 | - */ |
|
358 | - function getError(){ |
|
359 | - if($this->error_str != ''){ |
|
360 | - return $this->error_str; |
|
361 | - } |
|
362 | - return false; |
|
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * sets error string |
|
367 | - * |
|
368 | - * @return boolean $string error string |
|
369 | - * @access private |
|
370 | - */ |
|
371 | - function setError($str){ |
|
372 | - $this->error_str = $str; |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * detect if array is a simple array or a struct (associative array) |
|
377 | - * |
|
378 | - * @param mixed $val The PHP array |
|
379 | - * @return string (arraySimple|arrayStruct) |
|
380 | - * @access private |
|
381 | - */ |
|
382 | - function isArraySimpleOrStruct($val) { |
|
207 | + ); |
|
208 | + |
|
209 | + /** |
|
210 | + * XML entities to convert |
|
211 | + * |
|
212 | + * @var array |
|
213 | + * @access public |
|
214 | + * @deprecated |
|
215 | + * @see expandEntities |
|
216 | + */ |
|
217 | + var $xmlEntities = array('quot' => '"','amp' => '&', |
|
218 | + 'lt' => '<','gt' => '>','apos' => "'"); |
|
219 | + |
|
220 | + /** |
|
221 | + * constructor |
|
222 | + * |
|
223 | + * @access public |
|
224 | + */ |
|
225 | + function __construct() { |
|
226 | + $this->debugLevel = $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel']; |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * gets the global debug level, which applies to future instances |
|
231 | + * |
|
232 | + * @return integer Debug level 0-9, where 0 turns off |
|
233 | + * @access public |
|
234 | + */ |
|
235 | + function getGlobalDebugLevel() { |
|
236 | + return $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel']; |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * sets the global debug level, which applies to future instances |
|
241 | + * |
|
242 | + * @param int $level Debug level 0-9, where 0 turns off |
|
243 | + * @access public |
|
244 | + */ |
|
245 | + function setGlobalDebugLevel($level) { |
|
246 | + $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = $level; |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * gets the debug level for this instance |
|
251 | + * |
|
252 | + * @return int Debug level 0-9, where 0 turns off |
|
253 | + * @access public |
|
254 | + */ |
|
255 | + function getDebugLevel() { |
|
256 | + return $this->debugLevel; |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * sets the debug level for this instance |
|
261 | + * |
|
262 | + * @param int $level Debug level 0-9, where 0 turns off |
|
263 | + * @access public |
|
264 | + */ |
|
265 | + function setDebugLevel($level) { |
|
266 | + $this->debugLevel = $level; |
|
267 | + } |
|
268 | + |
|
269 | + /** |
|
270 | + * adds debug data to the instance debug string with formatting |
|
271 | + * |
|
272 | + * @param string $string debug data |
|
273 | + * @access private |
|
274 | + */ |
|
275 | + function debug($string){ |
|
276 | + if ($this->debugLevel > 0) { |
|
277 | + $this->appendDebug($this->getmicrotime().' '.get_class($this).": $string\n"); |
|
278 | + } |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * adds debug data to the instance debug string without formatting |
|
283 | + * |
|
284 | + * @param string $string debug data |
|
285 | + * @access public |
|
286 | + */ |
|
287 | + function appendDebug($string){ |
|
288 | + if ($this->debugLevel > 0) { |
|
289 | + // it would be nice to use a memory stream here to use |
|
290 | + // memory more efficiently |
|
291 | + $this->debug_str .= $string; |
|
292 | + } |
|
293 | + } |
|
294 | + |
|
295 | + /** |
|
296 | + * clears the current debug data for this instance |
|
297 | + * |
|
298 | + * @access public |
|
299 | + */ |
|
300 | + function clearDebug() { |
|
301 | + // it would be nice to use a memory stream here to use |
|
302 | + // memory more efficiently |
|
303 | + $this->debug_str = ''; |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * gets the current debug data for this instance |
|
308 | + * |
|
309 | + * @return debug data |
|
310 | + * @access public |
|
311 | + */ |
|
312 | + function &getDebug() { |
|
313 | + // it would be nice to use a memory stream here to use |
|
314 | + // memory more efficiently |
|
315 | + return $this->debug_str; |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * gets the current debug data for this instance as an XML comment |
|
320 | + * this may change the contents of the debug data |
|
321 | + * |
|
322 | + * @return debug data as an XML comment |
|
323 | + * @access public |
|
324 | + */ |
|
325 | + function &getDebugAsXMLComment() { |
|
326 | + // it would be nice to use a memory stream here to use |
|
327 | + // memory more efficiently |
|
328 | + while (strpos($this->debug_str, '--')) { |
|
329 | + $this->debug_str = str_replace('--', '- -', $this->debug_str); |
|
330 | + } |
|
331 | + $ret = "<!--\n" . $this->debug_str . "\n-->"; |
|
332 | + return $ret; |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * expands entities, e.g. changes '<' to '<'. |
|
337 | + * |
|
338 | + * @param string $val The string in which to expand entities. |
|
339 | + * @access private |
|
340 | + */ |
|
341 | + function expandEntities($val) { |
|
342 | + if ($this->charencoding) { |
|
343 | + $val = str_replace('&', '&', $val); |
|
344 | + $val = str_replace("'", ''', $val); |
|
345 | + $val = str_replace('"', '"', $val); |
|
346 | + $val = str_replace('<', '<', $val); |
|
347 | + $val = str_replace('>', '>', $val); |
|
348 | + } |
|
349 | + return $val; |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * returns error string if present |
|
354 | + * |
|
355 | + * @return mixed error string or false |
|
356 | + * @access public |
|
357 | + */ |
|
358 | + function getError(){ |
|
359 | + if($this->error_str != ''){ |
|
360 | + return $this->error_str; |
|
361 | + } |
|
362 | + return false; |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * sets error string |
|
367 | + * |
|
368 | + * @return boolean $string error string |
|
369 | + * @access private |
|
370 | + */ |
|
371 | + function setError($str){ |
|
372 | + $this->error_str = $str; |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * detect if array is a simple array or a struct (associative array) |
|
377 | + * |
|
378 | + * @param mixed $val The PHP array |
|
379 | + * @return string (arraySimple|arrayStruct) |
|
380 | + * @access private |
|
381 | + */ |
|
382 | + function isArraySimpleOrStruct($val) { |
|
383 | 383 | $keyList = array_keys($val); |
384 | - foreach ($keyList as $keyListValue) { |
|
385 | - if (!is_int($keyListValue)) { |
|
386 | - return 'arrayStruct'; |
|
387 | - } |
|
388 | - } |
|
389 | - return 'arraySimple'; |
|
390 | - } |
|
391 | - |
|
392 | - /** |
|
393 | - * serializes PHP values in accordance w/ section 5. Type information is |
|
394 | - * not serialized if $use == 'literal'. |
|
395 | - * |
|
396 | - * @param mixed $val The value to serialize |
|
397 | - * @param string $name The name (local part) of the XML element |
|
398 | - * @param string $type The XML schema type (local part) for the element |
|
399 | - * @param string $name_ns The namespace for the name of the XML element |
|
400 | - * @param string $type_ns The namespace for the type of the element |
|
401 | - * @param array $attributes The attributes to serialize as name=>value pairs |
|
402 | - * @param string $use The WSDL "use" (encoded|literal) |
|
403 | - * @param boolean $soapval Whether this is called from soapval. |
|
404 | - * @return string The serialized element, possibly with child elements |
|
405 | - * @access public |
|
406 | - */ |
|
407 | - function serialize_val($val,$name=false,$type=false,$name_ns=false,$type_ns=false,$attributes=false,$use='encoded',$soapval=false) { |
|
408 | - $this->debug("in serialize_val: name=$name, type=$type, name_ns=$name_ns, type_ns=$type_ns, use=$use, soapval=$soapval"); |
|
409 | - $this->appendDebug('value=' . $this->varDump($val)); |
|
410 | - $this->appendDebug('attributes=' . $this->varDump($attributes)); |
|
411 | - |
|
412 | - if (is_object($val) && get_class($val) == 'soapval' && (! $soapval)) { |
|
413 | - $this->debug("serialize_val: serialize soapval"); |
|
414 | - $xml = $val->serialize($use); |
|
415 | - $this->appendDebug($val->getDebug()); |
|
416 | - $val->clearDebug(); |
|
417 | - $this->debug("serialize_val of soapval returning $xml"); |
|
418 | - return $xml; |
|
384 | + foreach ($keyList as $keyListValue) { |
|
385 | + if (!is_int($keyListValue)) { |
|
386 | + return 'arrayStruct'; |
|
387 | + } |
|
419 | 388 | } |
420 | - // force valid name if necessary |
|
421 | - if (is_numeric($name)) { |
|
422 | - $name = '__numeric_' . $name; |
|
423 | - } elseif (! $name) { |
|
424 | - $name = 'noname'; |
|
425 | - } |
|
426 | - // if name has ns, add ns prefix to name |
|
427 | - $xmlns = ''; |
|
389 | + return 'arraySimple'; |
|
390 | + } |
|
391 | + |
|
392 | + /** |
|
393 | + * serializes PHP values in accordance w/ section 5. Type information is |
|
394 | + * not serialized if $use == 'literal'. |
|
395 | + * |
|
396 | + * @param mixed $val The value to serialize |
|
397 | + * @param string $name The name (local part) of the XML element |
|
398 | + * @param string $type The XML schema type (local part) for the element |
|
399 | + * @param string $name_ns The namespace for the name of the XML element |
|
400 | + * @param string $type_ns The namespace for the type of the element |
|
401 | + * @param array $attributes The attributes to serialize as name=>value pairs |
|
402 | + * @param string $use The WSDL "use" (encoded|literal) |
|
403 | + * @param boolean $soapval Whether this is called from soapval. |
|
404 | + * @return string The serialized element, possibly with child elements |
|
405 | + * @access public |
|
406 | + */ |
|
407 | + function serialize_val($val,$name=false,$type=false,$name_ns=false,$type_ns=false,$attributes=false,$use='encoded',$soapval=false) { |
|
408 | + $this->debug("in serialize_val: name=$name, type=$type, name_ns=$name_ns, type_ns=$type_ns, use=$use, soapval=$soapval"); |
|
409 | + $this->appendDebug('value=' . $this->varDump($val)); |
|
410 | + $this->appendDebug('attributes=' . $this->varDump($attributes)); |
|
411 | + |
|
412 | + if (is_object($val) && get_class($val) == 'soapval' && (! $soapval)) { |
|
413 | + $this->debug("serialize_val: serialize soapval"); |
|
414 | + $xml = $val->serialize($use); |
|
415 | + $this->appendDebug($val->getDebug()); |
|
416 | + $val->clearDebug(); |
|
417 | + $this->debug("serialize_val of soapval returning $xml"); |
|
418 | + return $xml; |
|
419 | + } |
|
420 | + // force valid name if necessary |
|
421 | + if (is_numeric($name)) { |
|
422 | + $name = '__numeric_' . $name; |
|
423 | + } elseif (! $name) { |
|
424 | + $name = 'noname'; |
|
425 | + } |
|
426 | + // if name has ns, add ns prefix to name |
|
427 | + $xmlns = ''; |
|
428 | 428 | if($name_ns){ |
429 | - $prefix = 'nu'.rand(1000,9999); |
|
430 | - $name = $prefix.':'.$name; |
|
431 | - $xmlns .= " xmlns:$prefix=\"$name_ns\""; |
|
432 | - } |
|
433 | - // if type is prefixed, create type prefix |
|
434 | - if($type_ns != '' && $type_ns == $this->namespaces['xsd']){ |
|
435 | - // need to fix this. shouldn't default to xsd if no ns specified |
|
436 | - // w/o checking against typemap |
|
437 | - $type_prefix = 'xsd'; |
|
438 | - } elseif($type_ns){ |
|
439 | - $type_prefix = 'ns'.rand(1000,9999); |
|
440 | - $xmlns .= " xmlns:$type_prefix=\"$type_ns\""; |
|
441 | - } |
|
442 | - // serialize attributes if present |
|
443 | - $atts = ''; |
|
444 | - if($attributes){ |
|
445 | - foreach($attributes as $k => $v){ |
|
446 | - $atts .= " $k=\"".$this->expandEntities($v).'"'; |
|
447 | - } |
|
448 | - } |
|
449 | - // serialize null value |
|
450 | - if (is_null($val)) { |
|
451 | - $this->debug("serialize_val: serialize null"); |
|
452 | - if ($use == 'literal') { |
|
453 | - // TODO: depends on minOccurs |
|
454 | - $xml = "<$name$xmlns$atts/>"; |
|
455 | - $this->debug("serialize_val returning $xml"); |
|
456 | - return $xml; |
|
457 | - } else { |
|
458 | - if (isset($type) && isset($type_prefix)) { |
|
459 | - $type_str = " xsi:type=\"$type_prefix:$type\""; |
|
460 | - } else { |
|
461 | - $type_str = ''; |
|
462 | - } |
|
463 | - $xml = "<$name$xmlns$type_str$atts xsi:nil=\"true\"/>"; |
|
464 | - $this->debug("serialize_val returning $xml"); |
|
465 | - return $xml; |
|
466 | - } |
|
467 | - } |
|
429 | + $prefix = 'nu'.rand(1000,9999); |
|
430 | + $name = $prefix.':'.$name; |
|
431 | + $xmlns .= " xmlns:$prefix=\"$name_ns\""; |
|
432 | + } |
|
433 | + // if type is prefixed, create type prefix |
|
434 | + if($type_ns != '' && $type_ns == $this->namespaces['xsd']){ |
|
435 | + // need to fix this. shouldn't default to xsd if no ns specified |
|
436 | + // w/o checking against typemap |
|
437 | + $type_prefix = 'xsd'; |
|
438 | + } elseif($type_ns){ |
|
439 | + $type_prefix = 'ns'.rand(1000,9999); |
|
440 | + $xmlns .= " xmlns:$type_prefix=\"$type_ns\""; |
|
441 | + } |
|
442 | + // serialize attributes if present |
|
443 | + $atts = ''; |
|
444 | + if($attributes){ |
|
445 | + foreach($attributes as $k => $v){ |
|
446 | + $atts .= " $k=\"".$this->expandEntities($v).'"'; |
|
447 | + } |
|
448 | + } |
|
449 | + // serialize null value |
|
450 | + if (is_null($val)) { |
|
451 | + $this->debug("serialize_val: serialize null"); |
|
452 | + if ($use == 'literal') { |
|
453 | + // TODO: depends on minOccurs |
|
454 | + $xml = "<$name$xmlns$atts/>"; |
|
455 | + $this->debug("serialize_val returning $xml"); |
|
456 | + return $xml; |
|
457 | + } else { |
|
458 | + if (isset($type) && isset($type_prefix)) { |
|
459 | + $type_str = " xsi:type=\"$type_prefix:$type\""; |
|
460 | + } else { |
|
461 | + $type_str = ''; |
|
462 | + } |
|
463 | + $xml = "<$name$xmlns$type_str$atts xsi:nil=\"true\"/>"; |
|
464 | + $this->debug("serialize_val returning $xml"); |
|
465 | + return $xml; |
|
466 | + } |
|
467 | + } |
|
468 | 468 | // serialize if an xsd built-in primitive type |
469 | 469 | if($type != '' && isset($this->typemap[$this->XMLSchemaVersion][$type])){ |
470 | - $this->debug("serialize_val: serialize xsd built-in primitive type"); |
|
471 | - if (is_bool($val)) { |
|
472 | - if ($type == 'boolean') { |
|
473 | - $val = $val ? 'true' : 'false'; |
|
474 | - } elseif (! $val) { |
|
475 | - $val = 0; |
|
476 | - } |
|
477 | - } else if (is_string($val)) { |
|
478 | - $val = $this->expandEntities($val); |
|
479 | - } |
|
480 | - if ($use == 'literal') { |
|
481 | - $xml = "<$name$xmlns$atts>$val</$name>"; |
|
482 | - $this->debug("serialize_val returning $xml"); |
|
483 | - return $xml; |
|
484 | - } else { |
|
485 | - $xml = "<$name$xmlns xsi:type=\"xsd:$type\"$atts>$val</$name>"; |
|
486 | - $this->debug("serialize_val returning $xml"); |
|
487 | - return $xml; |
|
488 | - } |
|
470 | + $this->debug("serialize_val: serialize xsd built-in primitive type"); |
|
471 | + if (is_bool($val)) { |
|
472 | + if ($type == 'boolean') { |
|
473 | + $val = $val ? 'true' : 'false'; |
|
474 | + } elseif (! $val) { |
|
475 | + $val = 0; |
|
476 | + } |
|
477 | + } else if (is_string($val)) { |
|
478 | + $val = $this->expandEntities($val); |
|
479 | + } |
|
480 | + if ($use == 'literal') { |
|
481 | + $xml = "<$name$xmlns$atts>$val</$name>"; |
|
482 | + $this->debug("serialize_val returning $xml"); |
|
483 | + return $xml; |
|
484 | + } else { |
|
485 | + $xml = "<$name$xmlns xsi:type=\"xsd:$type\"$atts>$val</$name>"; |
|
486 | + $this->debug("serialize_val returning $xml"); |
|
487 | + return $xml; |
|
488 | + } |
|
489 | 489 | } |
490 | - // detect type and serialize |
|
491 | - $xml = ''; |
|
492 | - switch(true) { |
|
493 | - case (is_bool($val) || $type == 'boolean'): |
|
494 | - $this->debug("serialize_val: serialize boolean"); |
|
495 | - if ($type == 'boolean') { |
|
496 | - $val = $val ? 'true' : 'false'; |
|
497 | - } elseif (! $val) { |
|
498 | - $val = 0; |
|
499 | - } |
|
500 | - if ($use == 'literal') { |
|
501 | - $xml .= "<$name$xmlns$atts>$val</$name>"; |
|
502 | - } else { |
|
503 | - $xml .= "<$name$xmlns xsi:type=\"xsd:boolean\"$atts>$val</$name>"; |
|
504 | - } |
|
505 | - break; |
|
506 | - case (is_int($val) || is_long($val) || $type == 'int'): |
|
507 | - $this->debug("serialize_val: serialize int"); |
|
508 | - if ($use == 'literal') { |
|
509 | - $xml .= "<$name$xmlns$atts>$val</$name>"; |
|
510 | - } else { |
|
511 | - $xml .= "<$name$xmlns xsi:type=\"xsd:int\"$atts>$val</$name>"; |
|
512 | - } |
|
513 | - break; |
|
514 | - case (is_float($val)|| is_double($val) || $type == 'float'): |
|
515 | - $this->debug("serialize_val: serialize float"); |
|
516 | - if ($use == 'literal') { |
|
517 | - $xml .= "<$name$xmlns$atts>$val</$name>"; |
|
518 | - } else { |
|
519 | - $xml .= "<$name$xmlns xsi:type=\"xsd:float\"$atts>$val</$name>"; |
|
520 | - } |
|
521 | - break; |
|
522 | - case (is_string($val) || $type == 'string'): |
|
523 | - $this->debug("serialize_val: serialize string"); |
|
524 | - $val = $this->expandEntities($val); |
|
525 | - if ($use == 'literal') { |
|
526 | - $xml .= "<$name$xmlns$atts>$val</$name>"; |
|
527 | - } else { |
|
528 | - $xml .= "<$name$xmlns xsi:type=\"xsd:string\"$atts>$val</$name>"; |
|
529 | - } |
|
530 | - break; |
|
531 | - case is_object($val): |
|
532 | - $this->debug("serialize_val: serialize object"); |
|
533 | - if (get_class($val) == 'soapval') { |
|
534 | - $this->debug("serialize_val: serialize soapval object"); |
|
535 | - $pXml = $val->serialize($use); |
|
536 | - $this->appendDebug($val->getDebug()); |
|
537 | - $val->clearDebug(); |
|
538 | - } else { |
|
539 | - if (! $name) { |
|
540 | - $name = get_class($val); |
|
541 | - $this->debug("In serialize_val, used class name $name as element name"); |
|
542 | - } else { |
|
543 | - $this->debug("In serialize_val, do not override name $name for element name for class " . get_class($val)); |
|
544 | - } |
|
545 | - foreach(get_object_vars($val) as $k => $v){ |
|
546 | - $pXml = isset($pXml) ? $pXml.$this->serialize_val($v,$k,false,false,false,false,$use) : $this->serialize_val($v,$k,false,false,false,false,$use); |
|
547 | - } |
|
548 | - } |
|
549 | - if(isset($type) && isset($type_prefix)){ |
|
550 | - $type_str = " xsi:type=\"$type_prefix:$type\""; |
|
551 | - } else { |
|
552 | - $type_str = ''; |
|
553 | - } |
|
554 | - if ($use == 'literal') { |
|
555 | - $xml .= "<$name$xmlns$atts>$pXml</$name>"; |
|
556 | - } else { |
|
557 | - $xml .= "<$name$xmlns$type_str$atts>$pXml</$name>"; |
|
558 | - } |
|
559 | - break; |
|
560 | - case (is_array($val) || $type): |
|
561 | - // detect if struct or array |
|
562 | - $valueType = $this->isArraySimpleOrStruct($val); |
|
490 | + // detect type and serialize |
|
491 | + $xml = ''; |
|
492 | + switch(true) { |
|
493 | + case (is_bool($val) || $type == 'boolean'): |
|
494 | + $this->debug("serialize_val: serialize boolean"); |
|
495 | + if ($type == 'boolean') { |
|
496 | + $val = $val ? 'true' : 'false'; |
|
497 | + } elseif (! $val) { |
|
498 | + $val = 0; |
|
499 | + } |
|
500 | + if ($use == 'literal') { |
|
501 | + $xml .= "<$name$xmlns$atts>$val</$name>"; |
|
502 | + } else { |
|
503 | + $xml .= "<$name$xmlns xsi:type=\"xsd:boolean\"$atts>$val</$name>"; |
|
504 | + } |
|
505 | + break; |
|
506 | + case (is_int($val) || is_long($val) || $type == 'int'): |
|
507 | + $this->debug("serialize_val: serialize int"); |
|
508 | + if ($use == 'literal') { |
|
509 | + $xml .= "<$name$xmlns$atts>$val</$name>"; |
|
510 | + } else { |
|
511 | + $xml .= "<$name$xmlns xsi:type=\"xsd:int\"$atts>$val</$name>"; |
|
512 | + } |
|
513 | + break; |
|
514 | + case (is_float($val)|| is_double($val) || $type == 'float'): |
|
515 | + $this->debug("serialize_val: serialize float"); |
|
516 | + if ($use == 'literal') { |
|
517 | + $xml .= "<$name$xmlns$atts>$val</$name>"; |
|
518 | + } else { |
|
519 | + $xml .= "<$name$xmlns xsi:type=\"xsd:float\"$atts>$val</$name>"; |
|
520 | + } |
|
521 | + break; |
|
522 | + case (is_string($val) || $type == 'string'): |
|
523 | + $this->debug("serialize_val: serialize string"); |
|
524 | + $val = $this->expandEntities($val); |
|
525 | + if ($use == 'literal') { |
|
526 | + $xml .= "<$name$xmlns$atts>$val</$name>"; |
|
527 | + } else { |
|
528 | + $xml .= "<$name$xmlns xsi:type=\"xsd:string\"$atts>$val</$name>"; |
|
529 | + } |
|
530 | + break; |
|
531 | + case is_object($val): |
|
532 | + $this->debug("serialize_val: serialize object"); |
|
533 | + if (get_class($val) == 'soapval') { |
|
534 | + $this->debug("serialize_val: serialize soapval object"); |
|
535 | + $pXml = $val->serialize($use); |
|
536 | + $this->appendDebug($val->getDebug()); |
|
537 | + $val->clearDebug(); |
|
538 | + } else { |
|
539 | + if (! $name) { |
|
540 | + $name = get_class($val); |
|
541 | + $this->debug("In serialize_val, used class name $name as element name"); |
|
542 | + } else { |
|
543 | + $this->debug("In serialize_val, do not override name $name for element name for class " . get_class($val)); |
|
544 | + } |
|
545 | + foreach(get_object_vars($val) as $k => $v){ |
|
546 | + $pXml = isset($pXml) ? $pXml.$this->serialize_val($v,$k,false,false,false,false,$use) : $this->serialize_val($v,$k,false,false,false,false,$use); |
|
547 | + } |
|
548 | + } |
|
549 | + if(isset($type) && isset($type_prefix)){ |
|
550 | + $type_str = " xsi:type=\"$type_prefix:$type\""; |
|
551 | + } else { |
|
552 | + $type_str = ''; |
|
553 | + } |
|
554 | + if ($use == 'literal') { |
|
555 | + $xml .= "<$name$xmlns$atts>$pXml</$name>"; |
|
556 | + } else { |
|
557 | + $xml .= "<$name$xmlns$type_str$atts>$pXml</$name>"; |
|
558 | + } |
|
559 | + break; |
|
560 | + case (is_array($val) || $type): |
|
561 | + // detect if struct or array |
|
562 | + $valueType = $this->isArraySimpleOrStruct($val); |
|
563 | 563 | if($valueType=='arraySimple' || preg_match('/^ArrayOf/',$type)){ |
564 | - $this->debug("serialize_val: serialize array"); |
|
565 | - $i = 0; |
|
566 | - if(is_array($val) && count($val)> 0){ |
|
567 | - foreach($val as $v){ |
|
568 | - if(is_object($v) && get_class($v) == 'soapval'){ |
|
569 | - $tt_ns = $v->type_ns; |
|
570 | - $tt = $v->type; |
|
571 | - } elseif (is_array($v)) { |
|
572 | - $tt = $this->isArraySimpleOrStruct($v); |
|
573 | - } else { |
|
574 | - $tt = gettype($v); |
|
575 | - } |
|
576 | - $array_types[$tt] = 1; |
|
577 | - // TODO: for literal, the name should be $name |
|
578 | - $xml .= $this->serialize_val($v,'item',false,false,false,false,$use); |
|
579 | - ++$i; |
|
580 | - } |
|
581 | - if(count($array_types) > 1){ |
|
582 | - $array_typename = 'xsd:anyType'; |
|
583 | - } elseif(isset($tt) && isset($this->typemap[$this->XMLSchemaVersion][$tt])) { |
|
584 | - if ($tt == 'integer') { |
|
585 | - $tt = 'int'; |
|
586 | - } |
|
587 | - $array_typename = 'xsd:'.$tt; |
|
588 | - } elseif(isset($tt) && $tt == 'arraySimple'){ |
|
589 | - $array_typename = 'SOAP-ENC:Array'; |
|
590 | - } elseif(isset($tt) && $tt == 'arrayStruct'){ |
|
591 | - $array_typename = 'unnamed_struct_use_soapval'; |
|
592 | - } else { |
|
593 | - // if type is prefixed, create type prefix |
|
594 | - if ($tt_ns != '' && $tt_ns == $this->namespaces['xsd']){ |
|
595 | - $array_typename = 'xsd:' . $tt; |
|
596 | - } elseif ($tt_ns) { |
|
597 | - $tt_prefix = 'ns' . rand(1000, 9999); |
|
598 | - $array_typename = "$tt_prefix:$tt"; |
|
599 | - $xmlns .= " xmlns:$tt_prefix=\"$tt_ns\""; |
|
600 | - } else { |
|
601 | - $array_typename = $tt; |
|
602 | - } |
|
603 | - } |
|
604 | - $array_type = $i; |
|
605 | - if ($use == 'literal') { |
|
606 | - $type_str = ''; |
|
607 | - } else if (isset($type) && isset($type_prefix)) { |
|
608 | - $type_str = " xsi:type=\"$type_prefix:$type\""; |
|
609 | - } else { |
|
610 | - $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"".$array_typename."[$array_type]\""; |
|
611 | - } |
|
612 | - // empty array |
|
613 | - } else { |
|
614 | - if ($use == 'literal') { |
|
615 | - $type_str = ''; |
|
616 | - } else if (isset($type) && isset($type_prefix)) { |
|
617 | - $type_str = " xsi:type=\"$type_prefix:$type\""; |
|
618 | - } else { |
|
619 | - $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"xsd:anyType[0]\""; |
|
620 | - } |
|
621 | - } |
|
622 | - // TODO: for array in literal, there is no wrapper here |
|
623 | - $xml = "<$name$xmlns$type_str$atts>".$xml."</$name>"; |
|
624 | - } else { |
|
625 | - // got a struct |
|
626 | - $this->debug("serialize_val: serialize struct"); |
|
627 | - if(isset($type) && isset($type_prefix)){ |
|
628 | - $type_str = " xsi:type=\"$type_prefix:$type\""; |
|
629 | - } else { |
|
630 | - $type_str = ''; |
|
631 | - } |
|
632 | - if ($use == 'literal') { |
|
633 | - $xml .= "<$name$xmlns$atts>"; |
|
634 | - } else { |
|
635 | - $xml .= "<$name$xmlns$type_str$atts>"; |
|
636 | - } |
|
637 | - foreach($val as $k => $v){ |
|
638 | - // Apache Map |
|
639 | - if ($type == 'Map' && $type_ns == 'http://xml.apache.org/xml-soap') { |
|
640 | - $xml .= '<item>'; |
|
641 | - $xml .= $this->serialize_val($k,'key',false,false,false,false,$use); |
|
642 | - $xml .= $this->serialize_val($v,'value',false,false,false,false,$use); |
|
643 | - $xml .= '</item>'; |
|
644 | - } else { |
|
645 | - $xml .= $this->serialize_val($v,$k,false,false,false,false,$use); |
|
646 | - } |
|
647 | - } |
|
648 | - $xml .= "</$name>"; |
|
649 | - } |
|
650 | - break; |
|
651 | - default: |
|
652 | - $this->debug("serialize_val: serialize unknown"); |
|
653 | - $xml .= 'not detected, got '.gettype($val).' for '.$val; |
|
654 | - break; |
|
655 | - } |
|
656 | - $this->debug("serialize_val returning $xml"); |
|
657 | - return $xml; |
|
658 | - } |
|
659 | - |
|
660 | - /** |
|
661 | - * serializes a message |
|
662 | - * |
|
663 | - * @param string $body the XML of the SOAP body |
|
664 | - * @param mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array |
|
665 | - * @param array $namespaces optional the namespaces used in generating the body and headers |
|
666 | - * @param string $style optional (rpc|document) |
|
667 | - * @param string $use optional (encoded|literal) |
|
668 | - * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded) |
|
669 | - * @return string the message |
|
670 | - * @access public |
|
671 | - */ |
|
564 | + $this->debug("serialize_val: serialize array"); |
|
565 | + $i = 0; |
|
566 | + if(is_array($val) && count($val)> 0){ |
|
567 | + foreach($val as $v){ |
|
568 | + if(is_object($v) && get_class($v) == 'soapval'){ |
|
569 | + $tt_ns = $v->type_ns; |
|
570 | + $tt = $v->type; |
|
571 | + } elseif (is_array($v)) { |
|
572 | + $tt = $this->isArraySimpleOrStruct($v); |
|
573 | + } else { |
|
574 | + $tt = gettype($v); |
|
575 | + } |
|
576 | + $array_types[$tt] = 1; |
|
577 | + // TODO: for literal, the name should be $name |
|
578 | + $xml .= $this->serialize_val($v,'item',false,false,false,false,$use); |
|
579 | + ++$i; |
|
580 | + } |
|
581 | + if(count($array_types) > 1){ |
|
582 | + $array_typename = 'xsd:anyType'; |
|
583 | + } elseif(isset($tt) && isset($this->typemap[$this->XMLSchemaVersion][$tt])) { |
|
584 | + if ($tt == 'integer') { |
|
585 | + $tt = 'int'; |
|
586 | + } |
|
587 | + $array_typename = 'xsd:'.$tt; |
|
588 | + } elseif(isset($tt) && $tt == 'arraySimple'){ |
|
589 | + $array_typename = 'SOAP-ENC:Array'; |
|
590 | + } elseif(isset($tt) && $tt == 'arrayStruct'){ |
|
591 | + $array_typename = 'unnamed_struct_use_soapval'; |
|
592 | + } else { |
|
593 | + // if type is prefixed, create type prefix |
|
594 | + if ($tt_ns != '' && $tt_ns == $this->namespaces['xsd']){ |
|
595 | + $array_typename = 'xsd:' . $tt; |
|
596 | + } elseif ($tt_ns) { |
|
597 | + $tt_prefix = 'ns' . rand(1000, 9999); |
|
598 | + $array_typename = "$tt_prefix:$tt"; |
|
599 | + $xmlns .= " xmlns:$tt_prefix=\"$tt_ns\""; |
|
600 | + } else { |
|
601 | + $array_typename = $tt; |
|
602 | + } |
|
603 | + } |
|
604 | + $array_type = $i; |
|
605 | + if ($use == 'literal') { |
|
606 | + $type_str = ''; |
|
607 | + } else if (isset($type) && isset($type_prefix)) { |
|
608 | + $type_str = " xsi:type=\"$type_prefix:$type\""; |
|
609 | + } else { |
|
610 | + $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"".$array_typename."[$array_type]\""; |
|
611 | + } |
|
612 | + // empty array |
|
613 | + } else { |
|
614 | + if ($use == 'literal') { |
|
615 | + $type_str = ''; |
|
616 | + } else if (isset($type) && isset($type_prefix)) { |
|
617 | + $type_str = " xsi:type=\"$type_prefix:$type\""; |
|
618 | + } else { |
|
619 | + $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"xsd:anyType[0]\""; |
|
620 | + } |
|
621 | + } |
|
622 | + // TODO: for array in literal, there is no wrapper here |
|
623 | + $xml = "<$name$xmlns$type_str$atts>".$xml."</$name>"; |
|
624 | + } else { |
|
625 | + // got a struct |
|
626 | + $this->debug("serialize_val: serialize struct"); |
|
627 | + if(isset($type) && isset($type_prefix)){ |
|
628 | + $type_str = " xsi:type=\"$type_prefix:$type\""; |
|
629 | + } else { |
|
630 | + $type_str = ''; |
|
631 | + } |
|
632 | + if ($use == 'literal') { |
|
633 | + $xml .= "<$name$xmlns$atts>"; |
|
634 | + } else { |
|
635 | + $xml .= "<$name$xmlns$type_str$atts>"; |
|
636 | + } |
|
637 | + foreach($val as $k => $v){ |
|
638 | + // Apache Map |
|
639 | + if ($type == 'Map' && $type_ns == 'http://xml.apache.org/xml-soap') { |
|
640 | + $xml .= '<item>'; |
|
641 | + $xml .= $this->serialize_val($k,'key',false,false,false,false,$use); |
|
642 | + $xml .= $this->serialize_val($v,'value',false,false,false,false,$use); |
|
643 | + $xml .= '</item>'; |
|
644 | + } else { |
|
645 | + $xml .= $this->serialize_val($v,$k,false,false,false,false,$use); |
|
646 | + } |
|
647 | + } |
|
648 | + $xml .= "</$name>"; |
|
649 | + } |
|
650 | + break; |
|
651 | + default: |
|
652 | + $this->debug("serialize_val: serialize unknown"); |
|
653 | + $xml .= 'not detected, got '.gettype($val).' for '.$val; |
|
654 | + break; |
|
655 | + } |
|
656 | + $this->debug("serialize_val returning $xml"); |
|
657 | + return $xml; |
|
658 | + } |
|
659 | + |
|
660 | + /** |
|
661 | + * serializes a message |
|
662 | + * |
|
663 | + * @param string $body the XML of the SOAP body |
|
664 | + * @param mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array |
|
665 | + * @param array $namespaces optional the namespaces used in generating the body and headers |
|
666 | + * @param string $style optional (rpc|document) |
|
667 | + * @param string $use optional (encoded|literal) |
|
668 | + * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded) |
|
669 | + * @return string the message |
|
670 | + * @access public |
|
671 | + */ |
|
672 | 672 | function serializeEnvelope($body,$headers=false,$namespaces=array(),$style='rpc',$use='encoded',$encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'){ |
673 | 673 | // TODO: add an option to automatically run utf8_encode on $body and $headers |
674 | 674 | // if $this->soap_defencoding is UTF-8. Not doing this automatically allows |
675 | 675 | // one to send arbitrary UTF-8 characters, not just characters that map to ISO-8859-1 |
676 | 676 | |
677 | - $this->debug("In serializeEnvelope length=" . strlen($body) . " body (max 1000 characters)=" . substr($body, 0, 1000) . " style=$style use=$use encodingStyle=$encodingStyle"); |
|
678 | - $this->debug("headers:"); |
|
679 | - $this->appendDebug($this->varDump($headers)); |
|
680 | - $this->debug("namespaces:"); |
|
681 | - $this->appendDebug($this->varDump($namespaces)); |
|
677 | + $this->debug("In serializeEnvelope length=" . strlen($body) . " body (max 1000 characters)=" . substr($body, 0, 1000) . " style=$style use=$use encodingStyle=$encodingStyle"); |
|
678 | + $this->debug("headers:"); |
|
679 | + $this->appendDebug($this->varDump($headers)); |
|
680 | + $this->debug("namespaces:"); |
|
681 | + $this->appendDebug($this->varDump($namespaces)); |
|
682 | 682 | |
683 | - // serialize namespaces |
|
683 | + // serialize namespaces |
|
684 | 684 | $ns_string = ''; |
685 | - foreach(array_merge($this->namespaces,$namespaces) as $k => $v){ |
|
686 | - $ns_string .= " xmlns:$k=\"$v\""; |
|
687 | - } |
|
688 | - if($encodingStyle) { |
|
689 | - $ns_string = " SOAP-ENV:encodingStyle=\"$encodingStyle\"$ns_string"; |
|
690 | - } |
|
691 | - |
|
692 | - // serialize headers |
|
693 | - if($headers){ |
|
694 | - if (is_array($headers)) { |
|
695 | - $xml = ''; |
|
696 | - foreach ($headers as $k => $v) { |
|
697 | - if (is_object($v) && get_class($v) == 'soapval') { |
|
698 | - $xml .= $this->serialize_val($v, false, false, false, false, false, $use); |
|
699 | - } else { |
|
700 | - $xml .= $this->serialize_val($v, $k, false, false, false, false, $use); |
|
701 | - } |
|
702 | - } |
|
703 | - $headers = $xml; |
|
704 | - $this->debug("In serializeEnvelope, serialized array of headers to $headers"); |
|
705 | - } |
|
706 | - $headers = "<SOAP-ENV:Header>".$headers."</SOAP-ENV:Header>"; |
|
707 | - } |
|
708 | - // serialize envelope |
|
709 | - return |
|
710 | - '<?xml version="1.0" encoding="'.$this->soap_defencoding .'"?'.">". |
|
711 | - '<SOAP-ENV:Envelope'.$ns_string.">". |
|
712 | - $headers. |
|
713 | - "<SOAP-ENV:Body>". |
|
714 | - $body. |
|
715 | - "</SOAP-ENV:Body>". |
|
716 | - "</SOAP-ENV:Envelope>"; |
|
717 | - } |
|
718 | - |
|
719 | - /** |
|
720 | - * formats a string to be inserted into an HTML stream |
|
721 | - * |
|
722 | - * @param string $str The string to format |
|
723 | - * @return string The formatted string |
|
724 | - * @access public |
|
725 | - * @deprecated |
|
726 | - */ |
|
685 | + foreach(array_merge($this->namespaces,$namespaces) as $k => $v){ |
|
686 | + $ns_string .= " xmlns:$k=\"$v\""; |
|
687 | + } |
|
688 | + if($encodingStyle) { |
|
689 | + $ns_string = " SOAP-ENV:encodingStyle=\"$encodingStyle\"$ns_string"; |
|
690 | + } |
|
691 | + |
|
692 | + // serialize headers |
|
693 | + if($headers){ |
|
694 | + if (is_array($headers)) { |
|
695 | + $xml = ''; |
|
696 | + foreach ($headers as $k => $v) { |
|
697 | + if (is_object($v) && get_class($v) == 'soapval') { |
|
698 | + $xml .= $this->serialize_val($v, false, false, false, false, false, $use); |
|
699 | + } else { |
|
700 | + $xml .= $this->serialize_val($v, $k, false, false, false, false, $use); |
|
701 | + } |
|
702 | + } |
|
703 | + $headers = $xml; |
|
704 | + $this->debug("In serializeEnvelope, serialized array of headers to $headers"); |
|
705 | + } |
|
706 | + $headers = "<SOAP-ENV:Header>".$headers."</SOAP-ENV:Header>"; |
|
707 | + } |
|
708 | + // serialize envelope |
|
709 | + return |
|
710 | + '<?xml version="1.0" encoding="'.$this->soap_defencoding .'"?'.">". |
|
711 | + '<SOAP-ENV:Envelope'.$ns_string.">". |
|
712 | + $headers. |
|
713 | + "<SOAP-ENV:Body>". |
|
714 | + $body. |
|
715 | + "</SOAP-ENV:Body>". |
|
716 | + "</SOAP-ENV:Envelope>"; |
|
717 | + } |
|
718 | + |
|
719 | + /** |
|
720 | + * formats a string to be inserted into an HTML stream |
|
721 | + * |
|
722 | + * @param string $str The string to format |
|
723 | + * @return string The formatted string |
|
724 | + * @access public |
|
725 | + * @deprecated |
|
726 | + */ |
|
727 | 727 | function formatDump($str){ |
728 | - $str = htmlspecialchars($str); |
|
729 | - return nl2br($str); |
|
730 | - } |
|
731 | - |
|
732 | - /** |
|
733 | - * contracts (changes namespace to prefix) a qualified name |
|
734 | - * |
|
735 | - * @param string $qname qname |
|
736 | - * @return string contracted qname |
|
737 | - * @access private |
|
738 | - */ |
|
739 | - function contractQname($qname){ |
|
740 | - // get element namespace |
|
741 | - //$this->xdebug("Contract $qname"); |
|
742 | - if (strrpos($qname, ':')) { |
|
743 | - // get unqualified name |
|
744 | - $name = substr($qname, strrpos($qname, ':') + 1); |
|
745 | - // get ns |
|
746 | - $ns = substr($qname, 0, strrpos($qname, ':')); |
|
747 | - $p = $this->getPrefixFromNamespace($ns); |
|
748 | - if ($p) { |
|
749 | - return $p . ':' . $name; |
|
750 | - } |
|
751 | - return $qname; |
|
752 | - } else { |
|
753 | - return $qname; |
|
754 | - } |
|
755 | - } |
|
756 | - |
|
757 | - /** |
|
758 | - * expands (changes prefix to namespace) a qualified name |
|
759 | - * |
|
760 | - * @param string $qname qname |
|
761 | - * @return string expanded qname |
|
762 | - * @access private |
|
763 | - */ |
|
764 | - function expandQname($qname){ |
|
765 | - // get element prefix |
|
766 | - if(strpos($qname,':') && !preg_match('/^http:\/\//',$qname)){ |
|
767 | - // get unqualified name |
|
768 | - $name = substr(strstr($qname,':'),1); |
|
769 | - // get ns prefix |
|
770 | - $prefix = substr($qname,0,strpos($qname,':')); |
|
771 | - if(isset($this->namespaces[$prefix])){ |
|
772 | - return $this->namespaces[$prefix].':'.$name; |
|
773 | - } else { |
|
774 | - return $qname; |
|
775 | - } |
|
776 | - } else { |
|
777 | - return $qname; |
|
778 | - } |
|
779 | - } |
|
780 | - |
|
781 | - /** |
|
782 | - * returns the local part of a prefixed string |
|
783 | - * returns the original string, if not prefixed |
|
784 | - * |
|
785 | - * @param string $str The prefixed string |
|
786 | - * @return string The local part |
|
787 | - * @access public |
|
788 | - */ |
|
789 | - function getLocalPart($str){ |
|
790 | - if($sstr = strrchr($str,':')){ |
|
791 | - // get unqualified name |
|
792 | - return substr( $sstr, 1 ); |
|
793 | - } else { |
|
794 | - return $str; |
|
795 | - } |
|
796 | - } |
|
797 | - |
|
798 | - /** |
|
799 | - * returns the prefix part of a prefixed string |
|
800 | - * returns false, if not prefixed |
|
801 | - * |
|
802 | - * @param string $str The prefixed string |
|
803 | - * @return mixed The prefix or false if there is no prefix |
|
804 | - * @access public |
|
805 | - */ |
|
806 | - function getPrefix($str){ |
|
807 | - if($pos = strrpos($str,':')){ |
|
808 | - // get prefix |
|
809 | - return substr($str,0,$pos); |
|
810 | - } |
|
811 | - return false; |
|
812 | - } |
|
813 | - |
|
814 | - /** |
|
815 | - * pass it a prefix, it returns a namespace |
|
816 | - * |
|
817 | - * @param string $prefix The prefix |
|
818 | - * @return mixed The namespace, false if no namespace has the specified prefix |
|
819 | - * @access public |
|
820 | - */ |
|
821 | - function getNamespaceFromPrefix($prefix){ |
|
822 | - if (isset($this->namespaces[$prefix])) { |
|
823 | - return $this->namespaces[$prefix]; |
|
824 | - } |
|
825 | - //$this->setError("No namespace registered for prefix '$prefix'"); |
|
826 | - return false; |
|
827 | - } |
|
828 | - |
|
829 | - /** |
|
830 | - * returns the prefix for a given namespace (or prefix) |
|
831 | - * or false if no prefixes registered for the given namespace |
|
832 | - * |
|
833 | - * @param string $ns The namespace |
|
834 | - * @return mixed The prefix, false if the namespace has no prefixes |
|
835 | - * @access public |
|
836 | - */ |
|
837 | - function getPrefixFromNamespace($ns) { |
|
838 | - foreach ($this->namespaces as $p => $n) { |
|
839 | - if ($ns == $n || $ns == $p) { |
|
840 | - $this->usedNamespaces[$p] = $n; |
|
841 | - return $p; |
|
842 | - } |
|
843 | - } |
|
844 | - return false; |
|
845 | - } |
|
846 | - |
|
847 | - /** |
|
848 | - * returns the time in ODBC canonical form with microseconds |
|
849 | - * |
|
850 | - * @return string The time in ODBC canonical form with microseconds |
|
851 | - * @access public |
|
852 | - */ |
|
853 | - function getmicrotime() { |
|
854 | - if (function_exists('gettimeofday')) { |
|
855 | - $tod = gettimeofday(); |
|
856 | - $sec = $tod['sec']; |
|
857 | - $usec = $tod['usec']; |
|
858 | - } else { |
|
859 | - $sec = time(); |
|
860 | - $usec = 0; |
|
861 | - } |
|
862 | - return strftime('%Y-%m-%d %H:%M:%S', $sec) . '.' . sprintf('%06d', $usec); |
|
863 | - } |
|
864 | - |
|
865 | - /** |
|
866 | - * Returns a string with the output of var_dump |
|
867 | - * |
|
868 | - * @param mixed $data The variable to var_dump |
|
869 | - * @return string The output of var_dump |
|
870 | - * @access public |
|
871 | - */ |
|
728 | + $str = htmlspecialchars($str); |
|
729 | + return nl2br($str); |
|
730 | + } |
|
731 | + |
|
732 | + /** |
|
733 | + * contracts (changes namespace to prefix) a qualified name |
|
734 | + * |
|
735 | + * @param string $qname qname |
|
736 | + * @return string contracted qname |
|
737 | + * @access private |
|
738 | + */ |
|
739 | + function contractQname($qname){ |
|
740 | + // get element namespace |
|
741 | + //$this->xdebug("Contract $qname"); |
|
742 | + if (strrpos($qname, ':')) { |
|
743 | + // get unqualified name |
|
744 | + $name = substr($qname, strrpos($qname, ':') + 1); |
|
745 | + // get ns |
|
746 | + $ns = substr($qname, 0, strrpos($qname, ':')); |
|
747 | + $p = $this->getPrefixFromNamespace($ns); |
|
748 | + if ($p) { |
|
749 | + return $p . ':' . $name; |
|
750 | + } |
|
751 | + return $qname; |
|
752 | + } else { |
|
753 | + return $qname; |
|
754 | + } |
|
755 | + } |
|
756 | + |
|
757 | + /** |
|
758 | + * expands (changes prefix to namespace) a qualified name |
|
759 | + * |
|
760 | + * @param string $qname qname |
|
761 | + * @return string expanded qname |
|
762 | + * @access private |
|
763 | + */ |
|
764 | + function expandQname($qname){ |
|
765 | + // get element prefix |
|
766 | + if(strpos($qname,':') && !preg_match('/^http:\/\//',$qname)){ |
|
767 | + // get unqualified name |
|
768 | + $name = substr(strstr($qname,':'),1); |
|
769 | + // get ns prefix |
|
770 | + $prefix = substr($qname,0,strpos($qname,':')); |
|
771 | + if(isset($this->namespaces[$prefix])){ |
|
772 | + return $this->namespaces[$prefix].':'.$name; |
|
773 | + } else { |
|
774 | + return $qname; |
|
775 | + } |
|
776 | + } else { |
|
777 | + return $qname; |
|
778 | + } |
|
779 | + } |
|
780 | + |
|
781 | + /** |
|
782 | + * returns the local part of a prefixed string |
|
783 | + * returns the original string, if not prefixed |
|
784 | + * |
|
785 | + * @param string $str The prefixed string |
|
786 | + * @return string The local part |
|
787 | + * @access public |
|
788 | + */ |
|
789 | + function getLocalPart($str){ |
|
790 | + if($sstr = strrchr($str,':')){ |
|
791 | + // get unqualified name |
|
792 | + return substr( $sstr, 1 ); |
|
793 | + } else { |
|
794 | + return $str; |
|
795 | + } |
|
796 | + } |
|
797 | + |
|
798 | + /** |
|
799 | + * returns the prefix part of a prefixed string |
|
800 | + * returns false, if not prefixed |
|
801 | + * |
|
802 | + * @param string $str The prefixed string |
|
803 | + * @return mixed The prefix or false if there is no prefix |
|
804 | + * @access public |
|
805 | + */ |
|
806 | + function getPrefix($str){ |
|
807 | + if($pos = strrpos($str,':')){ |
|
808 | + // get prefix |
|
809 | + return substr($str,0,$pos); |
|
810 | + } |
|
811 | + return false; |
|
812 | + } |
|
813 | + |
|
814 | + /** |
|
815 | + * pass it a prefix, it returns a namespace |
|
816 | + * |
|
817 | + * @param string $prefix The prefix |
|
818 | + * @return mixed The namespace, false if no namespace has the specified prefix |
|
819 | + * @access public |
|
820 | + */ |
|
821 | + function getNamespaceFromPrefix($prefix){ |
|
822 | + if (isset($this->namespaces[$prefix])) { |
|
823 | + return $this->namespaces[$prefix]; |
|
824 | + } |
|
825 | + //$this->setError("No namespace registered for prefix '$prefix'"); |
|
826 | + return false; |
|
827 | + } |
|
828 | + |
|
829 | + /** |
|
830 | + * returns the prefix for a given namespace (or prefix) |
|
831 | + * or false if no prefixes registered for the given namespace |
|
832 | + * |
|
833 | + * @param string $ns The namespace |
|
834 | + * @return mixed The prefix, false if the namespace has no prefixes |
|
835 | + * @access public |
|
836 | + */ |
|
837 | + function getPrefixFromNamespace($ns) { |
|
838 | + foreach ($this->namespaces as $p => $n) { |
|
839 | + if ($ns == $n || $ns == $p) { |
|
840 | + $this->usedNamespaces[$p] = $n; |
|
841 | + return $p; |
|
842 | + } |
|
843 | + } |
|
844 | + return false; |
|
845 | + } |
|
846 | + |
|
847 | + /** |
|
848 | + * returns the time in ODBC canonical form with microseconds |
|
849 | + * |
|
850 | + * @return string The time in ODBC canonical form with microseconds |
|
851 | + * @access public |
|
852 | + */ |
|
853 | + function getmicrotime() { |
|
854 | + if (function_exists('gettimeofday')) { |
|
855 | + $tod = gettimeofday(); |
|
856 | + $sec = $tod['sec']; |
|
857 | + $usec = $tod['usec']; |
|
858 | + } else { |
|
859 | + $sec = time(); |
|
860 | + $usec = 0; |
|
861 | + } |
|
862 | + return strftime('%Y-%m-%d %H:%M:%S', $sec) . '.' . sprintf('%06d', $usec); |
|
863 | + } |
|
864 | + |
|
865 | + /** |
|
866 | + * Returns a string with the output of var_dump |
|
867 | + * |
|
868 | + * @param mixed $data The variable to var_dump |
|
869 | + * @return string The output of var_dump |
|
870 | + * @access public |
|
871 | + */ |
|
872 | 872 | function varDump($data) { |
873 | - ob_start(); |
|
874 | - var_dump($data); |
|
875 | - $ret_val = ob_get_contents(); |
|
876 | - ob_end_clean(); |
|
877 | - return $ret_val; |
|
878 | - } |
|
879 | - |
|
880 | - /** |
|
881 | - * represents the object as a string |
|
882 | - * |
|
883 | - * @return string |
|
884 | - * @access public |
|
885 | - */ |
|
886 | - function __toString() { |
|
887 | - return $this->varDump($this); |
|
888 | - } |
|
873 | + ob_start(); |
|
874 | + var_dump($data); |
|
875 | + $ret_val = ob_get_contents(); |
|
876 | + ob_end_clean(); |
|
877 | + return $ret_val; |
|
878 | + } |
|
879 | + |
|
880 | + /** |
|
881 | + * represents the object as a string |
|
882 | + * |
|
883 | + * @return string |
|
884 | + * @access public |
|
885 | + */ |
|
886 | + function __toString() { |
|
887 | + return $this->varDump($this); |
|
888 | + } |
|
889 | 889 | } |
890 | 890 | |
891 | 891 | // XML Schema Datatype Helper Functions |
@@ -901,35 +901,35 @@ discard block |
||
901 | 901 | * @access public |
902 | 902 | */ |
903 | 903 | function timestamp_to_iso8601($timestamp,$utc=true){ |
904 | - $datestr = date('Y-m-d\TH:i:sO',$timestamp); |
|
905 | - $pos = strrpos($datestr, "+"); |
|
906 | - if ($pos === FALSE) { |
|
907 | - $pos = strrpos($datestr, "-"); |
|
908 | - } |
|
909 | - if ($pos !== FALSE) { |
|
910 | - if (strlen($datestr) == $pos + 5) { |
|
911 | - $datestr = substr($datestr, 0, $pos + 3) . ':' . substr($datestr, -2); |
|
912 | - } |
|
913 | - } |
|
914 | - if($utc){ |
|
915 | - $pattern = '/'. |
|
916 | - '([0-9]{4})-'. // centuries & years CCYY- |
|
917 | - '([0-9]{2})-'. // months MM- |
|
918 | - '([0-9]{2})'. // days DD |
|
919 | - 'T'. // separator T |
|
920 | - '([0-9]{2}):'. // hours hh: |
|
921 | - '([0-9]{2}):'. // minutes mm: |
|
922 | - '([0-9]{2})(\.[0-9]*)?'. // seconds ss.ss... |
|
923 | - '(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's |
|
924 | - '/'; |
|
925 | - |
|
926 | - if(preg_match($pattern,$datestr,$regs)){ |
|
927 | - return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ',$regs[1],$regs[2],$regs[3],$regs[4],$regs[5],$regs[6]); |
|
928 | - } |
|
929 | - return false; |
|
930 | - } else { |
|
931 | - return $datestr; |
|
932 | - } |
|
904 | + $datestr = date('Y-m-d\TH:i:sO',$timestamp); |
|
905 | + $pos = strrpos($datestr, "+"); |
|
906 | + if ($pos === FALSE) { |
|
907 | + $pos = strrpos($datestr, "-"); |
|
908 | + } |
|
909 | + if ($pos !== FALSE) { |
|
910 | + if (strlen($datestr) == $pos + 5) { |
|
911 | + $datestr = substr($datestr, 0, $pos + 3) . ':' . substr($datestr, -2); |
|
912 | + } |
|
913 | + } |
|
914 | + if($utc){ |
|
915 | + $pattern = '/'. |
|
916 | + '([0-9]{4})-'. // centuries & years CCYY- |
|
917 | + '([0-9]{2})-'. // months MM- |
|
918 | + '([0-9]{2})'. // days DD |
|
919 | + 'T'. // separator T |
|
920 | + '([0-9]{2}):'. // hours hh: |
|
921 | + '([0-9]{2}):'. // minutes mm: |
|
922 | + '([0-9]{2})(\.[0-9]*)?'. // seconds ss.ss... |
|
923 | + '(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's |
|
924 | + '/'; |
|
925 | + |
|
926 | + if(preg_match($pattern,$datestr,$regs)){ |
|
927 | + return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ',$regs[1],$regs[2],$regs[3],$regs[4],$regs[5],$regs[6]); |
|
928 | + } |
|
929 | + return false; |
|
930 | + } else { |
|
931 | + return $datestr; |
|
932 | + } |
|
933 | 933 | } |
934 | 934 | |
935 | 935 | /** |
@@ -940,35 +940,35 @@ discard block |
||
940 | 940 | * @access public |
941 | 941 | */ |
942 | 942 | function iso8601_to_timestamp($datestr){ |
943 | - $pattern = '/'. |
|
944 | - '([0-9]{4})-'. // centuries & years CCYY- |
|
945 | - '([0-9]{2})-'. // months MM- |
|
946 | - '([0-9]{2})'. // days DD |
|
947 | - 'T'. // separator T |
|
948 | - '([0-9]{2}):'. // hours hh: |
|
949 | - '([0-9]{2}):'. // minutes mm: |
|
950 | - '([0-9]{2})(\.[0-9]+)?'. // seconds ss.ss... |
|
951 | - '(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's |
|
952 | - '/'; |
|
953 | - if(preg_match($pattern,$datestr,$regs)){ |
|
954 | - // not utc |
|
955 | - if($regs[8] != 'Z'){ |
|
956 | - $op = substr($regs[8],0,1); |
|
957 | - $h = substr($regs[8],1,2); |
|
958 | - $m = substr($regs[8],strlen($regs[8])-2,2); |
|
959 | - if($op == '-'){ |
|
960 | - $regs[4] = $regs[4] + $h; |
|
961 | - $regs[5] = $regs[5] + $m; |
|
962 | - } elseif($op == '+'){ |
|
963 | - $regs[4] = $regs[4] - $h; |
|
964 | - $regs[5] = $regs[5] - $m; |
|
965 | - } |
|
966 | - } |
|
967 | - return gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); |
|
943 | + $pattern = '/'. |
|
944 | + '([0-9]{4})-'. // centuries & years CCYY- |
|
945 | + '([0-9]{2})-'. // months MM- |
|
946 | + '([0-9]{2})'. // days DD |
|
947 | + 'T'. // separator T |
|
948 | + '([0-9]{2}):'. // hours hh: |
|
949 | + '([0-9]{2}):'. // minutes mm: |
|
950 | + '([0-9]{2})(\.[0-9]+)?'. // seconds ss.ss... |
|
951 | + '(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's |
|
952 | + '/'; |
|
953 | + if(preg_match($pattern,$datestr,$regs)){ |
|
954 | + // not utc |
|
955 | + if($regs[8] != 'Z'){ |
|
956 | + $op = substr($regs[8],0,1); |
|
957 | + $h = substr($regs[8],1,2); |
|
958 | + $m = substr($regs[8],strlen($regs[8])-2,2); |
|
959 | + if($op == '-'){ |
|
960 | + $regs[4] = $regs[4] + $h; |
|
961 | + $regs[5] = $regs[5] + $m; |
|
962 | + } elseif($op == '+'){ |
|
963 | + $regs[4] = $regs[4] - $h; |
|
964 | + $regs[5] = $regs[5] - $m; |
|
965 | + } |
|
966 | + } |
|
967 | + return gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); |
|
968 | 968 | // return strtotime("$regs[1]-$regs[2]-$regs[3] $regs[4]:$regs[5]:$regs[6]Z"); |
969 | - } else { |
|
970 | - return false; |
|
971 | - } |
|
969 | + } else { |
|
970 | + return false; |
|
971 | + } |
|
972 | 972 | } |
973 | 973 | |
974 | 974 | /** |
@@ -980,13 +980,13 @@ discard block |
||
980 | 980 | */ |
981 | 981 | function usleepWindows($usec) |
982 | 982 | { |
983 | - $start = gettimeofday(); |
|
984 | - |
|
985 | - do |
|
986 | - { |
|
987 | - $stop = gettimeofday(); |
|
988 | - $timePassed = 1000000 * ($stop['sec'] - $start['sec']) |
|
989 | - + $stop['usec'] - $start['usec']; |
|
990 | - } |
|
991 | - while ($timePassed < $usec); |
|
983 | + $start = gettimeofday(); |
|
984 | + |
|
985 | + do |
|
986 | + { |
|
987 | + $stop = gettimeofday(); |
|
988 | + $timePassed = 1000000 * ($stop['sec'] - $start['sec']) |
|
989 | + + $stop['usec'] - $start['usec']; |
|
990 | + } |
|
991 | + while ($timePassed < $usec); |
|
992 | 992 | } |
@@ -726,29 +726,29 @@ discard block |
||
726 | 726 | } |
727 | 727 | |
728 | 728 | /** |
729 | - * Return an array of student state answers for fill the blank questions |
|
730 | - * for each students that answered the question |
|
731 | - * -2 : didn't answer |
|
732 | - * -1 : student answer is wrong |
|
733 | - * 0 : student answer is correct |
|
734 | - * >0 : for fill the blank question with choice menu, is the index of the student answer (right answer indice is 0) |
|
735 | - * |
|
736 | - * @param integer $testId |
|
737 | - * @param integer $questionId |
|
738 | - * @param $studentsIdList |
|
739 | - * @param string $startDate |
|
740 | - * @param string $endDate |
|
741 | - * @param bool $useLastAnswerredAttempt |
|
742 | - * @return array |
|
743 | - * ( |
|
744 | - * [student_id] => Array |
|
745 | - * ( |
|
746 | - * [first fill the blank for question] => -1 |
|
747 | - * [second fill the blank for question] => 2 |
|
748 | - * [third fill the blank for question] => -1 |
|
749 | - * ) |
|
750 | - * ) |
|
751 | - */ |
|
729 | + * Return an array of student state answers for fill the blank questions |
|
730 | + * for each students that answered the question |
|
731 | + * -2 : didn't answer |
|
732 | + * -1 : student answer is wrong |
|
733 | + * 0 : student answer is correct |
|
734 | + * >0 : for fill the blank question with choice menu, is the index of the student answer (right answer indice is 0) |
|
735 | + * |
|
736 | + * @param integer $testId |
|
737 | + * @param integer $questionId |
|
738 | + * @param $studentsIdList |
|
739 | + * @param string $startDate |
|
740 | + * @param string $endDate |
|
741 | + * @param bool $useLastAnswerredAttempt |
|
742 | + * @return array |
|
743 | + * ( |
|
744 | + * [student_id] => Array |
|
745 | + * ( |
|
746 | + * [first fill the blank for question] => -1 |
|
747 | + * [second fill the blank for question] => 2 |
|
748 | + * [third fill the blank for question] => -1 |
|
749 | + * ) |
|
750 | + * ) |
|
751 | + */ |
|
752 | 752 | public static function getFillTheBlankTabResult( |
753 | 753 | $testId, |
754 | 754 | $questionId, |
@@ -757,17 +757,17 @@ discard block |
||
757 | 757 | $endDate, |
758 | 758 | $useLastAnswerredAttempt = true |
759 | 759 | ) { |
760 | - $tblTrackEAttempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); |
|
761 | - $tblTrackEExercise = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); |
|
762 | - $courseId = api_get_course_int_id(); |
|
760 | + $tblTrackEAttempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); |
|
761 | + $tblTrackEExercise = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); |
|
762 | + $courseId = api_get_course_int_id(); |
|
763 | 763 | |
764 | 764 | |
765 | - // request to have all the answers of student for this question |
|
766 | - // student may have doing it several time |
|
767 | - // student may have not answered the bracket id, in this case, is result of the answer is empty |
|
765 | + // request to have all the answers of student for this question |
|
766 | + // student may have doing it several time |
|
767 | + // student may have not answered the bracket id, in this case, is result of the answer is empty |
|
768 | 768 | |
769 | - // we got the less recent attempt first |
|
770 | - $sql = ' |
|
769 | + // we got the less recent attempt first |
|
770 | + $sql = ' |
|
771 | 771 | SELECT * FROM '.$tblTrackEAttempt.' tea |
772 | 772 | LEFT JOIN '.$tblTrackEExercise.' tee |
773 | 773 | ON tee.exe_id = tea.exe_id |
@@ -782,51 +782,51 @@ discard block |
||
782 | 782 | ORDER BY user_id, tea.exe_id; |
783 | 783 | '; |
784 | 784 | |
785 | - $res = Database::query($sql); |
|
786 | - $tabUserResult = array(); |
|
787 | - $bracketNumber = 0; |
|
788 | - // foreach attempts for all students starting with his older attempt |
|
789 | - while ($data = Database::fetch_array($res)) { |
|
790 | - $tabAnswer = FillBlanks::getAnswerInfo($data['answer'], true); |
|
785 | + $res = Database::query($sql); |
|
786 | + $tabUserResult = array(); |
|
787 | + $bracketNumber = 0; |
|
788 | + // foreach attempts for all students starting with his older attempt |
|
789 | + while ($data = Database::fetch_array($res)) { |
|
790 | + $tabAnswer = FillBlanks::getAnswerInfo($data['answer'], true); |
|
791 | 791 | |
792 | - // for each bracket to find in this question |
|
793 | - foreach ($tabAnswer['studentanswer'] as $bracketNumber => $studentAnswer) { |
|
792 | + // for each bracket to find in this question |
|
793 | + foreach ($tabAnswer['studentanswer'] as $bracketNumber => $studentAnswer) { |
|
794 | 794 | |
795 | - if ($tabAnswer['studentanswer'][$bracketNumber] != '') { |
|
796 | - // student has answered this bracket, cool |
|
797 | - switch (FillBlanks::getFillTheBlankAnswerType($tabAnswer['tabwords'][$bracketNumber])) { |
|
798 | - case self::FILL_THE_BLANK_MENU : |
|
795 | + if ($tabAnswer['studentanswer'][$bracketNumber] != '') { |
|
796 | + // student has answered this bracket, cool |
|
797 | + switch (FillBlanks::getFillTheBlankAnswerType($tabAnswer['tabwords'][$bracketNumber])) { |
|
798 | + case self::FILL_THE_BLANK_MENU : |
|
799 | 799 | // get the indice of the choosen answer in the menu |
800 | 800 | // we know that the right answer is the first entry of the menu, ie 0 |
801 | 801 | // (remember, menu entries are shuffled when taking the test) |
802 | 802 | $tabUserResult[$data['user_id']][$bracketNumber] = FillBlanks::getFillTheBlankMenuAnswerNum( |
803 | - $tabAnswer['tabwords'][$bracketNumber], |
|
804 | - $tabAnswer['studentanswer'][$bracketNumber] |
|
805 | - ); |
|
806 | - break; |
|
807 | - default : |
|
803 | + $tabAnswer['tabwords'][$bracketNumber], |
|
804 | + $tabAnswer['studentanswer'][$bracketNumber] |
|
805 | + ); |
|
806 | + break; |
|
807 | + default : |
|
808 | 808 | if (FillBlanks::isGoodStudentAnswer($tabAnswer['studentanswer'][$bracketNumber], $tabAnswer['tabwords'][$bracketNumber])) { |
809 | - $tabUserResult[$data['user_id']][$bracketNumber] = 0; // right answer |
|
810 | - } else { |
|
811 | - $tabUserResult[$data['user_id']][$bracketNumber] = -1; // wrong answer |
|
812 | - } |
|
813 | - } |
|
814 | - } else { |
|
815 | - // student didn't answer this bracket |
|
816 | - if ($useLastAnswerredAttempt) { |
|
817 | - // if we take into account the last answered attempt |
|
818 | - if (!isset($tabUserResult[$data['user_id']][$bracketNumber])) { |
|
819 | - $tabUserResult[$data['user_id']][$bracketNumber] = -2; // not answered |
|
820 | - } |
|
821 | - } else { |
|
822 | - // we take the last attempt, even if the student answer the question before |
|
823 | - $tabUserResult[$data['user_id']][$bracketNumber] = -2; // not answered |
|
824 | - } |
|
825 | - } |
|
826 | - } |
|
827 | - } |
|
828 | - |
|
829 | - return $tabUserResult; |
|
809 | + $tabUserResult[$data['user_id']][$bracketNumber] = 0; // right answer |
|
810 | + } else { |
|
811 | + $tabUserResult[$data['user_id']][$bracketNumber] = -1; // wrong answer |
|
812 | + } |
|
813 | + } |
|
814 | + } else { |
|
815 | + // student didn't answer this bracket |
|
816 | + if ($useLastAnswerredAttempt) { |
|
817 | + // if we take into account the last answered attempt |
|
818 | + if (!isset($tabUserResult[$data['user_id']][$bracketNumber])) { |
|
819 | + $tabUserResult[$data['user_id']][$bracketNumber] = -2; // not answered |
|
820 | + } |
|
821 | + } else { |
|
822 | + // we take the last attempt, even if the student answer the question before |
|
823 | + $tabUserResult[$data['user_id']][$bracketNumber] = -2; // not answered |
|
824 | + } |
|
825 | + } |
|
826 | + } |
|
827 | + } |
|
828 | + |
|
829 | + return $tabUserResult; |
|
830 | 830 | } |
831 | 831 | |
832 | 832 | /** |
@@ -79,81 +79,81 @@ discard block |
||
79 | 79 | */ |
80 | 80 | if ($from_learnpath == 'yes') |
81 | 81 | { |
82 | - //start from clear every time in LearnPath Builder |
|
83 | - $_SESSION['addedresource'] = null; |
|
84 | - $_SESSION['addedresourceid'] = null; |
|
85 | - $_SESSION['addedresourceassigned'] = null; |
|
86 | - unset ($_SESSION['addedresource']); |
|
87 | - unset ($_SESSION['addedresourceid']); |
|
88 | - unset ($_SESSION['addedresourceassigned']); |
|
82 | + //start from clear every time in LearnPath Builder |
|
83 | + $_SESSION['addedresource'] = null; |
|
84 | + $_SESSION['addedresourceid'] = null; |
|
85 | + $_SESSION['addedresourceassigned'] = null; |
|
86 | + unset ($_SESSION['addedresource']); |
|
87 | + unset ($_SESSION['addedresourceid']); |
|
88 | + unset ($_SESSION['addedresourceassigned']); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | // Process a new chapter? |
92 | 92 | if (!empty ($_POST['add_dir']) && !empty ($_POST['title'])) |
93 | 93 | { |
94 | - $title = $_POST['title']; |
|
95 | - $description = ''; |
|
96 | - if (!empty ($_POST['description'])) |
|
97 | - { |
|
98 | - $description = $_POST['description']; |
|
99 | - } |
|
100 | - |
|
101 | - // get max display_order so far in this parent chapter |
|
102 | - $sql = "SELECT MAX(display_order) FROM $tbl_learnpath_chapter WHERE learnpath_id = $learnpath_id "." AND parent_chapter_id = $chapter_id"; |
|
103 | - $res = Database::query($sql); |
|
104 | - $row = Database::fetch_array($res); |
|
105 | - $max_temp = $row[0]; |
|
106 | - |
|
107 | - $sql = "SELECT MAX(display_order) FROM $tbl_learnpath_item WHERE "." chapter_id = $chapter_id"; |
|
108 | - $res = Database::query($sql); |
|
109 | - $row = Database::fetch_array($res); |
|
110 | - $max_temp2 = $row[0]; |
|
111 | - if ($max_temp2 > $max_temp) |
|
112 | - { |
|
113 | - $order = $max_temp2 +1; |
|
114 | - } |
|
115 | - else |
|
116 | - { |
|
117 | - $order = $max_temp +1; |
|
118 | - } |
|
119 | - |
|
120 | - $sql = "INSERT INTO $tbl_learnpath_chapter "."(learnpath_id,chapter_name,chapter_description,parent_chapter_id,display_order) "." VALUES "."($learnpath_id, '$title', '$description', $chapter_id, $order )"; |
|
121 | - $res = Database::query($sql); |
|
122 | - if ($res !== false) |
|
123 | - { |
|
124 | - $title = ''; |
|
125 | - $description = ''; |
|
126 | - } |
|
94 | + $title = $_POST['title']; |
|
95 | + $description = ''; |
|
96 | + if (!empty ($_POST['description'])) |
|
97 | + { |
|
98 | + $description = $_POST['description']; |
|
99 | + } |
|
100 | + |
|
101 | + // get max display_order so far in this parent chapter |
|
102 | + $sql = "SELECT MAX(display_order) FROM $tbl_learnpath_chapter WHERE learnpath_id = $learnpath_id "." AND parent_chapter_id = $chapter_id"; |
|
103 | + $res = Database::query($sql); |
|
104 | + $row = Database::fetch_array($res); |
|
105 | + $max_temp = $row[0]; |
|
106 | + |
|
107 | + $sql = "SELECT MAX(display_order) FROM $tbl_learnpath_item WHERE "." chapter_id = $chapter_id"; |
|
108 | + $res = Database::query($sql); |
|
109 | + $row = Database::fetch_array($res); |
|
110 | + $max_temp2 = $row[0]; |
|
111 | + if ($max_temp2 > $max_temp) |
|
112 | + { |
|
113 | + $order = $max_temp2 +1; |
|
114 | + } |
|
115 | + else |
|
116 | + { |
|
117 | + $order = $max_temp +1; |
|
118 | + } |
|
119 | + |
|
120 | + $sql = "INSERT INTO $tbl_learnpath_chapter "."(learnpath_id,chapter_name,chapter_description,parent_chapter_id,display_order) "." VALUES "."($learnpath_id, '$title', '$description', $chapter_id, $order )"; |
|
121 | + $res = Database::query($sql); |
|
122 | + if ($res !== false) |
|
123 | + { |
|
124 | + $title = ''; |
|
125 | + $description = ''; |
|
126 | + } |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | // This if when a external link is submitted |
130 | 130 | if (!empty ($_POST['external_link_submit'])) |
131 | 131 | { |
132 | - $add = true; |
|
133 | - if ($add_2_links != "niet toevoegen") |
|
134 | - { |
|
135 | - // add external link to the links table. |
|
136 | - $pos = strpos($external_link, 'ttp:'); |
|
137 | - if ($pos == '') |
|
138 | - { |
|
139 | - $external_link = 'http://'.$external_link; |
|
140 | - } |
|
141 | - |
|
142 | - $sql = "INSERT INTO $link_table (url, title, category_id) VALUES ('$external_link','$external_link','$add_2_links')"; |
|
143 | - $result = Database::query($sql); |
|
144 | - $addedresource[] = "Link"; |
|
145 | - $addedresourceid[] = Database::insert_id(); |
|
146 | - $_SESSION['addedresource'] = $addedresource; |
|
147 | - $_SESSION['addedresourceid'] = $addedresourceid; |
|
148 | - } |
|
149 | - else |
|
150 | - { |
|
151 | - // do not add external link to the links table |
|
152 | - $addedresource[] = "Externallink"; |
|
153 | - $addedresourceid[] = $external_link; |
|
154 | - $_SESSION['addedresource'] = $addedresource; |
|
155 | - $_SESSION['addedresourceid'] = $addedresourceid; |
|
156 | - } |
|
132 | + $add = true; |
|
133 | + if ($add_2_links != "niet toevoegen") |
|
134 | + { |
|
135 | + // add external link to the links table. |
|
136 | + $pos = strpos($external_link, 'ttp:'); |
|
137 | + if ($pos == '') |
|
138 | + { |
|
139 | + $external_link = 'http://'.$external_link; |
|
140 | + } |
|
141 | + |
|
142 | + $sql = "INSERT INTO $link_table (url, title, category_id) VALUES ('$external_link','$external_link','$add_2_links')"; |
|
143 | + $result = Database::query($sql); |
|
144 | + $addedresource[] = "Link"; |
|
145 | + $addedresourceid[] = Database::insert_id(); |
|
146 | + $_SESSION['addedresource'] = $addedresource; |
|
147 | + $_SESSION['addedresourceid'] = $addedresourceid; |
|
148 | + } |
|
149 | + else |
|
150 | + { |
|
151 | + // do not add external link to the links table |
|
152 | + $addedresource[] = "Externallink"; |
|
153 | + $addedresourceid[] = $external_link; |
|
154 | + $_SESSION['addedresource'] = $addedresource; |
|
155 | + $_SESSION['addedresourceid'] = $addedresourceid; |
|
156 | + } |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | // loading the session variables into local array |
@@ -163,107 +163,107 @@ discard block |
||
163 | 163 | // This is when a resource was added to the session |
164 | 164 | if ($add) |
165 | 165 | { |
166 | - // adding the new variable to the local array |
|
167 | - if (empty ($_POST['external_link_submit'])) |
|
168 | - { |
|
169 | - //that case is already arranged, see upwards |
|
170 | - $addedresource[] = $content; |
|
171 | - $addedresourceid[] = $add; |
|
172 | - } |
|
173 | - $addedresourceassigned[] = 0; |
|
174 | - |
|
175 | - // loading the local array into the session variable |
|
176 | - $_SESSION['addedresource'] = $addedresource; |
|
177 | - $_SESSION['addedresourceid'] = $addedresourceid; |
|
166 | + // adding the new variable to the local array |
|
167 | + if (empty ($_POST['external_link_submit'])) |
|
168 | + { |
|
169 | + //that case is already arranged, see upwards |
|
170 | + $addedresource[] = $content; |
|
171 | + $addedresourceid[] = $add; |
|
172 | + } |
|
173 | + $addedresourceassigned[] = 0; |
|
174 | + |
|
175 | + // loading the local array into the session variable |
|
176 | + $_SESSION['addedresource'] = $addedresource; |
|
177 | + $_SESSION['addedresourceid'] = $addedresourceid; |
|
178 | + |
|
179 | + //--------------------------------------- |
|
180 | + //we assign to chapters immediately ! |
|
181 | + //--------------------------------------- |
|
182 | + $resource_added = false; |
|
183 | + if ($from_learnpath == 'yes') |
|
184 | + { |
|
185 | + $i = 0; |
|
186 | + //calculating the last order of the items of this chapter |
|
187 | + $sql = "SELECT MAX(display_order) FROM $tbl_learnpath_item WHERE chapter_id=$chapter_id"; |
|
188 | + $result = Database::query($sql); |
|
189 | + if(Database::num_rows($result)==0){ |
|
190 | + $lastorder_item = 0; |
|
191 | + }else{ |
|
192 | + $row = Database::fetch_array($result); |
|
193 | + $lastorder_item = ($row[0]); |
|
194 | + } |
|
195 | + $sql = "SELECT MAX(display_order) FROM $tbl_learnpath_chapter WHERE parent_chapter_id=$chapter_id"; |
|
196 | + $result = Database::query($sql); |
|
197 | + if(Database::num_rows($result)==0){ |
|
198 | + $lastorder_chapter = 0; |
|
199 | + }else{ |
|
200 | + $row = Database::fetch_array($result); |
|
201 | + $lastorder_chapter = ($row[0]); |
|
202 | + } |
|
203 | + $lastorder = ($lastorder_chapter>$lastorder_item?$lastorder_chapter+1:$lastorder_item+1); |
|
178 | 204 | |
179 | - //--------------------------------------- |
|
180 | - //we assign to chapters immediately ! |
|
181 | - //--------------------------------------- |
|
182 | - $resource_added = false; |
|
183 | - if ($from_learnpath == 'yes') |
|
184 | - { |
|
185 | - $i = 0; |
|
186 | - //calculating the last order of the items of this chapter |
|
187 | - $sql = "SELECT MAX(display_order) FROM $tbl_learnpath_item WHERE chapter_id=$chapter_id"; |
|
188 | - $result = Database::query($sql); |
|
189 | - if(Database::num_rows($result)==0){ |
|
190 | - $lastorder_item = 0; |
|
191 | - }else{ |
|
192 | - $row = Database::fetch_array($result); |
|
193 | - $lastorder_item = ($row[0]); |
|
194 | - } |
|
195 | - $sql = "SELECT MAX(display_order) FROM $tbl_learnpath_chapter WHERE parent_chapter_id=$chapter_id"; |
|
196 | - $result = Database::query($sql); |
|
197 | - if(Database::num_rows($result)==0){ |
|
198 | - $lastorder_chapter = 0; |
|
199 | - }else{ |
|
200 | - $row = Database::fetch_array($result); |
|
201 | - $lastorder_chapter = ($row[0]); |
|
202 | - } |
|
203 | - $lastorder = ($lastorder_chapter>$lastorder_item?$lastorder_chapter+1:$lastorder_item+1); |
|
204 | - |
|
205 | - foreach ($addedresource as $addedresource_item) |
|
206 | - { |
|
207 | - // in the case we added a chapter, add this into the chapters list with the correct parent_id |
|
208 | - if ($addedresource_item == "Chap") |
|
209 | - { |
|
210 | - $sql = "INSERT INTO $tbl_learnpath_chapter ("."'learnpath_id','chapter_name','chapter_description','parent_chapter_id','display_order'".") VALUES (".$learnpath_id.",'".$learnpath_chapter_name."','".$learnpath_chapter_description."',".$chapter_id.",".$lastorder.")"; |
|
211 | - Database::query($sql); |
|
212 | - } |
|
213 | - |
|
214 | - if (!$addedresourceassigned[$i]) |
|
215 | - { |
|
216 | - //not to assign it twice |
|
217 | - if ($addedresource_item == "Ass") |
|
218 | - { |
|
219 | - $addedresource_item = "Assignments"; |
|
220 | - } |
|
221 | - if ($addedresource_item == "Drop") |
|
222 | - { |
|
223 | - $addedresource_item = "Dropbox"; |
|
224 | - } |
|
225 | - if ($addedresource_item == "Intro") |
|
226 | - { |
|
227 | - $addedresource_item = "Introduction_text"; |
|
228 | - } |
|
229 | - if ($addedresource_item == "Course_desc") |
|
230 | - { |
|
231 | - $addedresource_item = "Course_description"; |
|
232 | - } |
|
233 | - if ($addedresource_item == "Group") |
|
234 | - { |
|
235 | - $addedresource_item = "Groups"; |
|
236 | - } |
|
237 | - if ($addedresource_item == "User") |
|
238 | - { |
|
239 | - $addedresource_item = "Users"; |
|
240 | - } |
|
241 | - if ($target == '') |
|
242 | - { |
|
243 | - $target = '_self'; |
|
244 | - } |
|
245 | - if ($addedresource_item == 'Link') |
|
246 | - { |
|
247 | - $addedresource_item .= ' '.$target; |
|
248 | - } |
|
249 | - $sql = "INSERT INTO $tbl_learnpath_item (id, chapter_id, item_type, item_id, display_order) VALUES ( '$autoid', '$chapter_id', '$addedresource_item','$addedresourceid[$i]','".$lastorder."')"; |
|
250 | - $result = Database::query($sql); |
|
251 | - $addedresourceassigned[$i] = 1; |
|
252 | - $resource_added = true; |
|
253 | - } |
|
254 | - $i ++; |
|
255 | - $lastorder ++; |
|
256 | - } |
|
257 | - //$_SESSION['addedresource']=null; |
|
258 | - //$_SESSION['addedresourceid']=null; |
|
259 | - // cleaning up the session once again |
|
260 | - $_SESSION['addedresource'] = null; |
|
261 | - $_SESSION['addedresourceid'] = null; |
|
262 | - $_SESSION['addedresourceassigned'] = null; |
|
263 | - unset ($_SESSION['addedresource']); |
|
264 | - unset ($_SESSION['addedresourceid']); |
|
265 | - unset ($_SESSION['addedresourceassigned']); |
|
266 | - } |
|
205 | + foreach ($addedresource as $addedresource_item) |
|
206 | + { |
|
207 | + // in the case we added a chapter, add this into the chapters list with the correct parent_id |
|
208 | + if ($addedresource_item == "Chap") |
|
209 | + { |
|
210 | + $sql = "INSERT INTO $tbl_learnpath_chapter ("."'learnpath_id','chapter_name','chapter_description','parent_chapter_id','display_order'".") VALUES (".$learnpath_id.",'".$learnpath_chapter_name."','".$learnpath_chapter_description."',".$chapter_id.",".$lastorder.")"; |
|
211 | + Database::query($sql); |
|
212 | + } |
|
213 | + |
|
214 | + if (!$addedresourceassigned[$i]) |
|
215 | + { |
|
216 | + //not to assign it twice |
|
217 | + if ($addedresource_item == "Ass") |
|
218 | + { |
|
219 | + $addedresource_item = "Assignments"; |
|
220 | + } |
|
221 | + if ($addedresource_item == "Drop") |
|
222 | + { |
|
223 | + $addedresource_item = "Dropbox"; |
|
224 | + } |
|
225 | + if ($addedresource_item == "Intro") |
|
226 | + { |
|
227 | + $addedresource_item = "Introduction_text"; |
|
228 | + } |
|
229 | + if ($addedresource_item == "Course_desc") |
|
230 | + { |
|
231 | + $addedresource_item = "Course_description"; |
|
232 | + } |
|
233 | + if ($addedresource_item == "Group") |
|
234 | + { |
|
235 | + $addedresource_item = "Groups"; |
|
236 | + } |
|
237 | + if ($addedresource_item == "User") |
|
238 | + { |
|
239 | + $addedresource_item = "Users"; |
|
240 | + } |
|
241 | + if ($target == '') |
|
242 | + { |
|
243 | + $target = '_self'; |
|
244 | + } |
|
245 | + if ($addedresource_item == 'Link') |
|
246 | + { |
|
247 | + $addedresource_item .= ' '.$target; |
|
248 | + } |
|
249 | + $sql = "INSERT INTO $tbl_learnpath_item (id, chapter_id, item_type, item_id, display_order) VALUES ( '$autoid', '$chapter_id', '$addedresource_item','$addedresourceid[$i]','".$lastorder."')"; |
|
250 | + $result = Database::query($sql); |
|
251 | + $addedresourceassigned[$i] = 1; |
|
252 | + $resource_added = true; |
|
253 | + } |
|
254 | + $i ++; |
|
255 | + $lastorder ++; |
|
256 | + } |
|
257 | + //$_SESSION['addedresource']=null; |
|
258 | + //$_SESSION['addedresourceid']=null; |
|
259 | + // cleaning up the session once again |
|
260 | + $_SESSION['addedresource'] = null; |
|
261 | + $_SESSION['addedresourceid'] = null; |
|
262 | + $_SESSION['addedresourceassigned'] = null; |
|
263 | + unset ($_SESSION['addedresource']); |
|
264 | + unset ($_SESSION['addedresourceid']); |
|
265 | + unset ($_SESSION['addedresourceassigned']); |
|
266 | + } |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /* |
@@ -278,64 +278,64 @@ discard block |
||
278 | 278 | */ |
279 | 279 | if ($_GET["source_id"]) |
280 | 280 | { |
281 | - switch ($_GET["source_id"]) |
|
282 | - { |
|
283 | - case "1" : // coming from Agenda |
|
284 | - if ($action == "edit") |
|
285 | - { |
|
286 | - $url = "../calendar/agenda.php?action=edit&id=49&originalresource=$originalresource"; |
|
287 | - } |
|
288 | - elseif ($action == "add") |
|
289 | - { |
|
290 | - $url = "../calendar/agenda.php?action=add&originalresource=$originalresource"; |
|
291 | - } |
|
292 | - else |
|
293 | - { |
|
294 | - $url = "../calendar/agenda.php?action=add"; |
|
295 | - } |
|
296 | - $originaltoolname = get_lang("Agenda"); |
|
297 | - $breadcrumbelement = array ("url" => $url, "name" => $originaltoolname); |
|
298 | - unset($_SESSION['from_learnpath']); |
|
299 | - unset ($from_learnpath); |
|
300 | - break; |
|
301 | - case "2" : // coming from forum: new topic |
|
302 | - $url = "../phpbb/newtopic.php?forum=$source_forum&md5=$md5"; |
|
303 | - $originaltoolname = get_lang("ForumAddNewTopic"); |
|
304 | - $breadcrumbelement = array ("url" => $url, "name" => $originaltoolname); |
|
305 | - unset($_SESSION['from_learnpath']); |
|
306 | - unset ($from_learnpath); |
|
307 | - break; |
|
308 | - case "3" : // coming from forum: edit topic |
|
309 | - $url = "../phpbb/editpost.php?post_id=$post_id&topic=$topic&forum=$forum&md5=$md5&originalresource=no"; |
|
310 | - $originaltoolname = get_lang("ForumEditTopic"); |
|
311 | - $breadcrumbelement = array ("url" => $url, "name" => $originaltoolname); |
|
312 | - unset($_SESSION['from_learnpath']); |
|
313 | - unset ($from_learnpath); |
|
314 | - break; |
|
315 | - case "4" : // coming from exercises: edit topic |
|
316 | - $url = "../exercise/admin.php?modifyAnswers=$modifyAnswers"; |
|
317 | - $originaltoolname = get_lang("ExerciseAnswers"); |
|
318 | - $breadcrumbelement = array ("url" => $url, "name" => $originaltoolname); |
|
319 | - unset($_SESSION['from_learnpath']); |
|
320 | - unset ($from_learnpath); |
|
321 | - break; |
|
322 | - case "5" : // coming from learning path |
|
323 | - $from_learnpath = 'yes'; |
|
324 | - Session::write('from_learnpath',$from_learnpath); |
|
325 | - break; |
|
326 | - /*************************************** end add [email protected] *********************************/ |
|
327 | - |
|
328 | - } |
|
329 | - // We do not come from the learning path. We store the name of the tool & url in a session. |
|
330 | - if ($from_learnpath != 'yes') |
|
331 | - { |
|
332 | - if (!$_SESSION["origintoolurl"] OR $_SESSION["origintoolurl"]<>$interbreadcrumb["url"]) |
|
333 | - { |
|
334 | - $_SESSION["origintoolurl"] = $breadcrumbelement["url"]; |
|
335 | - $_SESSION["origintoolname"] = $breadcrumbelement["name"]; |
|
336 | - $interbreadcrumb = ""; |
|
337 | - } |
|
338 | - } |
|
281 | + switch ($_GET["source_id"]) |
|
282 | + { |
|
283 | + case "1" : // coming from Agenda |
|
284 | + if ($action == "edit") |
|
285 | + { |
|
286 | + $url = "../calendar/agenda.php?action=edit&id=49&originalresource=$originalresource"; |
|
287 | + } |
|
288 | + elseif ($action == "add") |
|
289 | + { |
|
290 | + $url = "../calendar/agenda.php?action=add&originalresource=$originalresource"; |
|
291 | + } |
|
292 | + else |
|
293 | + { |
|
294 | + $url = "../calendar/agenda.php?action=add"; |
|
295 | + } |
|
296 | + $originaltoolname = get_lang("Agenda"); |
|
297 | + $breadcrumbelement = array ("url" => $url, "name" => $originaltoolname); |
|
298 | + unset($_SESSION['from_learnpath']); |
|
299 | + unset ($from_learnpath); |
|
300 | + break; |
|
301 | + case "2" : // coming from forum: new topic |
|
302 | + $url = "../phpbb/newtopic.php?forum=$source_forum&md5=$md5"; |
|
303 | + $originaltoolname = get_lang("ForumAddNewTopic"); |
|
304 | + $breadcrumbelement = array ("url" => $url, "name" => $originaltoolname); |
|
305 | + unset($_SESSION['from_learnpath']); |
|
306 | + unset ($from_learnpath); |
|
307 | + break; |
|
308 | + case "3" : // coming from forum: edit topic |
|
309 | + $url = "../phpbb/editpost.php?post_id=$post_id&topic=$topic&forum=$forum&md5=$md5&originalresource=no"; |
|
310 | + $originaltoolname = get_lang("ForumEditTopic"); |
|
311 | + $breadcrumbelement = array ("url" => $url, "name" => $originaltoolname); |
|
312 | + unset($_SESSION['from_learnpath']); |
|
313 | + unset ($from_learnpath); |
|
314 | + break; |
|
315 | + case "4" : // coming from exercises: edit topic |
|
316 | + $url = "../exercise/admin.php?modifyAnswers=$modifyAnswers"; |
|
317 | + $originaltoolname = get_lang("ExerciseAnswers"); |
|
318 | + $breadcrumbelement = array ("url" => $url, "name" => $originaltoolname); |
|
319 | + unset($_SESSION['from_learnpath']); |
|
320 | + unset ($from_learnpath); |
|
321 | + break; |
|
322 | + case "5" : // coming from learning path |
|
323 | + $from_learnpath = 'yes'; |
|
324 | + Session::write('from_learnpath',$from_learnpath); |
|
325 | + break; |
|
326 | + /*************************************** end add [email protected] *********************************/ |
|
327 | + |
|
328 | + } |
|
329 | + // We do not come from the learning path. We store the name of the tool & url in a session. |
|
330 | + if ($from_learnpath != 'yes') |
|
331 | + { |
|
332 | + if (!$_SESSION["origintoolurl"] OR $_SESSION["origintoolurl"]<>$interbreadcrumb["url"]) |
|
333 | + { |
|
334 | + $_SESSION["origintoolurl"] = $breadcrumbelement["url"]; |
|
335 | + $_SESSION["origintoolname"] = $breadcrumbelement["name"]; |
|
336 | + $interbreadcrumb = ""; |
|
337 | + } |
|
338 | + } |
|
339 | 339 | |
340 | 340 | } |
341 | 341 | |
@@ -343,26 +343,26 @@ discard block |
||
343 | 343 | // the information from the session. Else we use the information of the learningpath itself. |
344 | 344 | if ($from_learnpath != 'yes') |
345 | 345 | { |
346 | - $nameTools = get_lang('AddResource'); |
|
347 | - $interbreadcrumb[] = array ("url" => $_SESSION["origintoolurl"], "name" => $_SESSION["origintoolname"]); |
|
346 | + $nameTools = get_lang('AddResource'); |
|
347 | + $interbreadcrumb[] = array ("url" => $_SESSION["origintoolurl"], "name" => $_SESSION["origintoolname"]); |
|
348 | 348 | } |
349 | 349 | else |
350 | 350 | { |
351 | - $learnpath_select_query = " SELECT * FROM $tbl_learnpath_main |
|
351 | + $learnpath_select_query = " SELECT * FROM $tbl_learnpath_main |
|
352 | 352 | WHERE learnpath_id=$learnpath_id"; |
353 | - $sql_result = Database::query($learnpath_select_query); |
|
354 | - $therow = Database::fetch_array($sql_result); |
|
353 | + $sql_result = Database::query($learnpath_select_query); |
|
354 | + $therow = Database::fetch_array($sql_result); |
|
355 | 355 | |
356 | - $learnpath_chapter_query = " SELECT * FROM $tbl_learnpath_chapter |
|
356 | + $learnpath_chapter_query = " SELECT * FROM $tbl_learnpath_chapter |
|
357 | 357 | WHERE (learnpath_id = '$learnpath_id' and id = '$chapter_id')"; |
358 | - $sql_result = Database::query($learnpath_chapter_query); |
|
359 | - $therow2 = Database::fetch_array($sql_result); |
|
358 | + $sql_result = Database::query($learnpath_chapter_query); |
|
359 | + $therow2 = Database::fetch_array($sql_result); |
|
360 | 360 | |
361 | - $from_learnpath = 'yes'; |
|
362 | - $_SESSION['from_learnpath'] = $from_learnpath; |
|
363 | - $interbreadcrumb[] = array ("url" => "../scorm/scormdocument.php", "name" => get_lang('LearningPath')); |
|
364 | - $interbreadcrumb[] = array ("url" => "../learnpath/learnpath_handler.php?learnpath_id=$learnpath_id", "name" => "{$therow['learnpath_name']}"); |
|
365 | - $interbreadcrumb[] = array ("url" => api_get_self()."?action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no", "name" => "{$therow2['chapter_name']}"); |
|
361 | + $from_learnpath = 'yes'; |
|
362 | + $_SESSION['from_learnpath'] = $from_learnpath; |
|
363 | + $interbreadcrumb[] = array ("url" => "../scorm/scormdocument.php", "name" => get_lang('LearningPath')); |
|
364 | + $interbreadcrumb[] = array ("url" => "../learnpath/learnpath_handler.php?learnpath_id=$learnpath_id", "name" => "{$therow['learnpath_name']}"); |
|
365 | + $interbreadcrumb[] = array ("url" => api_get_self()."?action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no", "name" => "{$therow2['chapter_name']}"); |
|
366 | 366 | |
367 | 367 | } |
368 | 368 | |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | echo "<h3>".$nameTools; |
381 | 381 | if ($from_learnpath == 'yes') |
382 | 382 | { |
383 | - echo get_lang("AddResource")." - {$therow2['chapter_name']}"; |
|
383 | + echo get_lang("AddResource")." - {$therow2['chapter_name']}"; |
|
384 | 384 | } |
385 | 385 | echo "</h3>"; |
386 | 386 | |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | $result_select_active=Database::query($sql_select_active); |
394 | 394 | while ($row=Database::fetch_array($result_select_active)) |
395 | 395 | { |
396 | - $active_modules[]=$row['name']; |
|
396 | + $active_modules[]=$row['name']; |
|
397 | 397 | } |
398 | 398 | |
399 | 399 | |
@@ -536,12 +536,12 @@ discard block |
||
536 | 536 | |
537 | 537 | if ($from_learnpath != 'yes') |
538 | 538 | { |
539 | - echo "<tr><td> </td></tr>"; |
|
540 | - echo "<tr><td><b>".get_lang('ResourcesAdded')." ("; |
|
541 | - echo count($addedresource); |
|
542 | - echo ")</b></td></tr>"; |
|
543 | - echo "<tr><td nowrap><a href=\"".api_get_self()."?showresources=true&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('ShowDelete')."</a>"; |
|
544 | - echo "</td></tr>"; |
|
539 | + echo "<tr><td> </td></tr>"; |
|
540 | + echo "<tr><td><b>".get_lang('ResourcesAdded')." ("; |
|
541 | + echo count($addedresource); |
|
542 | + echo ")</b></td></tr>"; |
|
543 | + echo "<tr><td nowrap><a href=\"".api_get_self()."?showresources=true&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('ShowDelete')."</a>"; |
|
544 | + echo "</td></tr>"; |
|
545 | 545 | } |
546 | 546 | ?> |
547 | 547 | <tr> |
@@ -557,11 +557,11 @@ discard block |
||
557 | 557 | |
558 | 558 | if ($from_learnpath != 'yes') |
559 | 559 | { |
560 | - echo "<form method=\"post\" action=\"{$_SESSION['origintoolurl']}\" style=\"margin: 0px;\"><input type=\"submit\" value=\"".get_lang('Ok')."\"></form>"; |
|
560 | + echo "<form method=\"post\" action=\"{$_SESSION['origintoolurl']}\" style=\"margin: 0px;\"><input type=\"submit\" value=\"".get_lang('Ok')."\"></form>"; |
|
561 | 561 | } |
562 | 562 | else |
563 | 563 | { |
564 | - echo "<form method=\"get\" action=\"../learnpath/learnpath_handler.php\" style=\"margin: 0px;\"><input type=\"hidden\" name=\"learnpath_id\" value=\"".htmlentities($learnpath_id)."\"><input type=\"submit\" value=\"".' '.get_lang('Ok').' '."\"></form>"; |
|
564 | + echo "<form method=\"get\" action=\"../learnpath/learnpath_handler.php\" style=\"margin: 0px;\"><input type=\"hidden\" name=\"learnpath_id\" value=\"".htmlentities($learnpath_id)."\"><input type=\"submit\" value=\"".' '.get_lang('Ok').' '."\"></form>"; |
|
565 | 565 | } |
566 | 566 | ?> |
567 | 567 | |
@@ -577,40 +577,40 @@ discard block |
||
577 | 577 | |
578 | 578 | if ($resource_added) |
579 | 579 | { |
580 | - Display :: display_normal_message(get_lang("ResourceAdded")); |
|
580 | + Display :: display_normal_message(get_lang("ResourceAdded")); |
|
581 | 581 | } |
582 | 582 | |
583 | 583 | if ($from_learnpath != 'yes') |
584 | 584 | { |
585 | - echo count($addedresource)." ".api_strtolower(get_lang('ResourcesAdded'))."<br/>"; |
|
585 | + echo count($addedresource)." ".api_strtolower(get_lang('ResourcesAdded'))."<br/>"; |
|
586 | 586 | } |
587 | 587 | //echo "<hr>"; |
588 | 588 | |
589 | 589 | // Agenda items --> |
590 | 590 | if ($content == "Agenda") |
591 | 591 | { |
592 | - $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA); |
|
593 | - $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); |
|
592 | + $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA); |
|
593 | + $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); |
|
594 | 594 | |
595 | - $sql="SELECT agenda.*, toolitemproperties.* |
|
595 | + $sql="SELECT agenda.*, toolitemproperties.* |
|
596 | 596 | FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties |
597 | 597 | WHERE agenda.id = toolitemproperties.ref |
598 | 598 | AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."' |
599 | 599 | AND (toolitemproperties.to_group_id='0' OR toolitemproperties.to_group_id IS NULL) |
600 | 600 | AND toolitemproperties.visibility='1'"; |
601 | 601 | |
602 | - $result = Database::query($sql); |
|
603 | - |
|
604 | - while ($myrow = Database::fetch_array($result)) |
|
605 | - { |
|
606 | - echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\">"; |
|
607 | - echo "<img src='../img/agenda.gif' alt='agenda'>"; |
|
608 | - echo api_convert_and_format_date($myrow["start_date"], null, date_default_timezone_get())."<br />"; |
|
609 | - echo "<b>".$myrow["title"]."</b></td></tr><tr><td>"; |
|
610 | - echo $myrow["content"]."<br />"; |
|
611 | - showorhide_addresourcelink($content, $myrow["id"]); |
|
612 | - echo "</td></tr></table><br />"; |
|
613 | - } |
|
602 | + $result = Database::query($sql); |
|
603 | + |
|
604 | + while ($myrow = Database::fetch_array($result)) |
|
605 | + { |
|
606 | + echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\">"; |
|
607 | + echo "<img src='../img/agenda.gif' alt='agenda'>"; |
|
608 | + echo api_convert_and_format_date($myrow["start_date"], null, date_default_timezone_get())."<br />"; |
|
609 | + echo "<b>".$myrow["title"]."</b></td></tr><tr><td>"; |
|
610 | + echo $myrow["content"]."<br />"; |
|
611 | + showorhide_addresourcelink($content, $myrow["id"]); |
|
612 | + echo "</td></tr></table><br />"; |
|
613 | + } |
|
614 | 614 | } // end if ($_GET["resource"]=="Agenda") |
615 | 615 | |
616 | 616 | /* |
@@ -620,12 +620,12 @@ discard block |
||
620 | 620 | */ |
621 | 621 | if ($content == "chapter") |
622 | 622 | { |
623 | - echo '<table><form name="add_dir" action="'.'" method="POST">'."\n"; |
|
624 | - echo ' <tr><td>'.get_lang('Title').'</td><td><input type="text" name="title" value="'.$title.'"></input></td></tr>'."\n"; |
|
625 | - echo ' <tr><td>'.get_lang('Description').'</td><td><input type="text" name="description" value="'.$description.'"></input></td></tr>'."\n"; |
|
626 | - echo ' <tr><td></td><td><input type="submit" name="add_dir" value="'.get_lang('AddIt').'"/></td></tr>'."\n"; |
|
627 | - echo '</form></table>'."\n"; |
|
628 | - //echo "<hr>"; |
|
623 | + echo '<table><form name="add_dir" action="'.'" method="POST">'."\n"; |
|
624 | + echo ' <tr><td>'.get_lang('Title').'</td><td><input type="text" name="title" value="'.$title.'"></input></td></tr>'."\n"; |
|
625 | + echo ' <tr><td>'.get_lang('Description').'</td><td><input type="text" name="description" value="'.$description.'"></input></td></tr>'."\n"; |
|
626 | + echo ' <tr><td></td><td><input type="submit" name="add_dir" value="'.get_lang('AddIt').'"/></td></tr>'."\n"; |
|
627 | + echo '</form></table>'."\n"; |
|
628 | + //echo "<hr>"; |
|
629 | 629 | } |
630 | 630 | |
631 | 631 | /* |
@@ -640,23 +640,23 @@ discard block |
||
640 | 640 | // b. one is a student AND the documents tool is active. Student cannot add documents if the documents tool is inactive (teacher can do this) |
641 | 641 | if ($content == "Document" OR (empty($content) AND (api_is_allowed_to_edit() OR in_array(TOOL_DOCUMENT,$active_modules))) AND !$_GET['showresources']) |
642 | 642 | { |
643 | - // setting variables for file locations |
|
644 | - $baseServDir = $_configuration['root_sys']; |
|
645 | - $courseDir = $_course['path']."/document"; |
|
646 | - $baseWorkDir = $baseServDir.$courseDir; |
|
647 | - // showing the link to move one folder up (when not in the root folder) |
|
648 | - show_folder_up($chapter_id); |
|
649 | - // showing the blue bar with the path in it when we are not in the root |
|
650 | - if (get_levels($folder)) |
|
651 | - { |
|
652 | - echo "<table width=\"100%\"><tr><td bgcolor=\"#4171B5\">"; |
|
653 | - echo "<img src=\"../img/opendir.gif\" alt='directory'><font color=\"#ffffff\"><b>"; |
|
654 | - echo $folder."</b></font></td></tr></table>"; |
|
655 | - } |
|
656 | - |
|
657 | - // showing the documents and subfolders of the folder we are in. |
|
658 | - show_documents($folder, $chapter_id); |
|
659 | - //echo "<hr>"; |
|
643 | + // setting variables for file locations |
|
644 | + $baseServDir = $_configuration['root_sys']; |
|
645 | + $courseDir = $_course['path']."/document"; |
|
646 | + $baseWorkDir = $baseServDir.$courseDir; |
|
647 | + // showing the link to move one folder up (when not in the root folder) |
|
648 | + show_folder_up($chapter_id); |
|
649 | + // showing the blue bar with the path in it when we are not in the root |
|
650 | + if (get_levels($folder)) |
|
651 | + { |
|
652 | + echo "<table width=\"100%\"><tr><td bgcolor=\"#4171B5\">"; |
|
653 | + echo "<img src=\"../img/opendir.gif\" alt='directory'><font color=\"#ffffff\"><b>"; |
|
654 | + echo $folder."</b></font></td></tr></table>"; |
|
655 | + } |
|
656 | + |
|
657 | + // showing the documents and subfolders of the folder we are in. |
|
658 | + show_documents($folder, $chapter_id); |
|
659 | + //echo "<hr>"; |
|
660 | 660 | } |
661 | 661 | |
662 | 662 | /* |
@@ -666,8 +666,8 @@ discard block |
||
666 | 666 | */ |
667 | 667 | if ($content == "Ad_Valvas") |
668 | 668 | { |
669 | - $tbl_announcement = Database :: get_course_table(TABLE_ANNOUNCEMENT); |
|
670 | - $sql = "SELECT * FROM ".$tbl_announcement." a, ".$item_property_table." i |
|
669 | + $tbl_announcement = Database :: get_course_table(TABLE_ANNOUNCEMENT); |
|
670 | + $sql = "SELECT * FROM ".$tbl_announcement." a, ".$item_property_table." i |
|
671 | 671 | WHERE |
672 | 672 | i.tool = '".TOOL_ANNOUNCEMENT."' AND |
673 | 673 | a.id=i.ref AND |
@@ -676,17 +676,17 @@ discard block |
||
676 | 676 | i.to_user_id IS NULL |
677 | 677 | ORDER BY a.display_order ASC"; |
678 | 678 | |
679 | - $result = Database::query($sql); |
|
680 | - while ($myrow = Database::fetch_array($result)) |
|
681 | - { |
|
682 | - echo "<table width=\"100%\"><tr><td>"; |
|
683 | - echo "<img src='../img/valves.gif' alt='advalvas'>"; |
|
684 | - echo api_convert_and_format_date($myrow["end_date"], DATE_FORMAT_LONG, date_default_timezone_get()); |
|
685 | - echo "</td></tr><tr><td>"; |
|
686 | - echo $myrow["title"]."<br />"; |
|
687 | - showorhide_addresourcelink($content, $myrow["id"]); |
|
688 | - echo "</td></tr></table>"; |
|
689 | - } |
|
679 | + $result = Database::query($sql); |
|
680 | + while ($myrow = Database::fetch_array($result)) |
|
681 | + { |
|
682 | + echo "<table width=\"100%\"><tr><td>"; |
|
683 | + echo "<img src='../img/valves.gif' alt='advalvas'>"; |
|
684 | + echo api_convert_and_format_date($myrow["end_date"], DATE_FORMAT_LONG, date_default_timezone_get()); |
|
685 | + echo "</td></tr><tr><td>"; |
|
686 | + echo $myrow["title"]."<br />"; |
|
687 | + showorhide_addresourcelink($content, $myrow["id"]); |
|
688 | + echo "</td></tr></table>"; |
|
689 | + } |
|
690 | 690 | } |
691 | 691 | |
692 | 692 | /* |
@@ -696,75 +696,75 @@ discard block |
||
696 | 696 | */ |
697 | 697 | if ($content == "Forum") |
698 | 698 | { |
699 | - $TBL_FORUMS = Database::get_course_table(TABLE_FORUM); |
|
700 | - $TBL_CATAGORIES = Database::get_course_table(TABLE_FORUM_CATEGORY); |
|
701 | - $TBL_FORUMTOPICS = Database::get_course_table(TABLE_FORUM_POST); |
|
702 | - $tbl_posts = Database::get_course_table(TABLE_FORUM_POST); |
|
703 | - $tbl_posts_text = Database::get_course_table(TOOL_FORUM_POST_TEXT_TABLE); |
|
704 | - |
|
705 | - echo "<table width='100%'>"; |
|
699 | + $TBL_FORUMS = Database::get_course_table(TABLE_FORUM); |
|
700 | + $TBL_CATAGORIES = Database::get_course_table(TABLE_FORUM_CATEGORY); |
|
701 | + $TBL_FORUMTOPICS = Database::get_course_table(TABLE_FORUM_POST); |
|
702 | + $tbl_posts = Database::get_course_table(TABLE_FORUM_POST); |
|
703 | + $tbl_posts_text = Database::get_course_table(TOOL_FORUM_POST_TEXT_TABLE); |
|
704 | + |
|
705 | + echo "<table width='100%'>"; |
|
706 | + |
|
707 | + // displaying the categories and the forums |
|
708 | + if (!$forum and !$thread) |
|
709 | + { |
|
710 | + $sql = "SELECT * FROM ".$TBL_FORUMS." forums, ".$TBL_CATAGORIES." categories WHERE forums.cat_id=categories.cat_id ORDER BY forums.cat_id DESC"; |
|
711 | + $result = Database::query($sql); |
|
712 | + while ($myrow = Database::fetch_array($result)) |
|
713 | + { |
|
714 | + if ($myrow["cat_title"] !== $old_cat_title) |
|
715 | + { |
|
716 | + echo "<tr><td bgcolor='#4171B5' colspan='2'><font color='white'><b>".$myrow["cat_title"]."</b></font></td></tr>"; |
|
717 | + } |
|
718 | + $old_cat_title = $myrow["cat_title"]; |
|
719 | + echo "<tr><td><img src='../img/forum.gif'><a href='".api_get_self()."?content=Forum&category=".$myrow["cat_id"]."&forum=".$myrow["forum_id"]."&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".$myrow["forum_name"]."</td><td>"; |
|
720 | + showorhide_addresourcelink("Forum", $myrow["forum_id"]); |
|
721 | + echo "</td></tr>"; |
|
722 | + } |
|
723 | + } |
|
724 | + //displaying all the threads of one forum |
|
725 | + if ($forum) |
|
726 | + { |
|
727 | + // displaying the category title |
|
728 | + $sql = "SELECT * FROM ".$TBL_CATAGORIES." WHERE cat_id=$category"; |
|
729 | + $result = Database::query($sql); |
|
730 | + $myrow = Database::fetch_array($result); |
|
731 | + echo "<tr><td bgcolor='#4171B5' colspan='2'><font color='white'><b>".$myrow["cat_title"]."</b></font></td></tr>"; |
|
732 | + |
|
733 | + // displaying the forum title |
|
734 | + $sql = "SELECT * FROM ".$TBL_FORUMS." forums, ".$TBL_FORUMTOPICS." topics WHERE forums.forum_id=topics.forum_id"; |
|
735 | + $result = Database::query($sql); |
|
736 | + $myrow = Database::fetch_array($result); |
|
737 | + echo "<tr><td bgcolor='#cccccc' colspan='2'><b>".$myrow["forum_name"]."</b></td></tr>"; |
|
738 | + |
|
739 | + if (!$thread) |
|
740 | + { |
|
741 | + // displaying all the threads of this forum |
|
742 | + $sql = "SELECT * FROM ".$TBL_FORUMTOPICS." WHERE forum_id=$forum"; |
|
743 | + $result = Database::query($sql); |
|
744 | + while ($myrow = Database::fetch_array($result)) |
|
745 | + { |
|
746 | + echo "<tr><td><a href='".api_get_self()."?content=Forum&category=$category&forum=1&thread=".$myrow["topic_id"]."&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".$myrow["topic_title"]."</a> (".$myrow["prenom"]." ".$myrow["nom"].")</td><td>"; |
|
747 | + showorhide_addresourcelink("Thread", $myrow["topic_id"]); |
|
748 | + echo "</td></tr>"; |
|
749 | + } |
|
750 | + } |
|
751 | + else |
|
752 | + { |
|
753 | + // displaying all the replies |
|
754 | + $sql = "SELECT * FROM ".$tbl_posts." post, ".$tbl_posts_text." post_text WHERE post_text.post_id=post.post_id and post.topic_id=$thread ORDER BY post_text.post_id ASC"; |
|
755 | + $result = Database::query($sql); |
|
756 | + while ($myrow = Database::fetch_array($result)) |
|
757 | + { |
|
758 | + echo "<tr><td><b>".$myrow["post_title"]."</b><br>"; |
|
759 | + echo $myrow["post_text"]."</td>"; |
|
760 | + echo "<td>"; |
|
761 | + showorhide_addresourcelink("Post", $myrow["post_id"]); |
|
762 | + echo "</td></tr><tr><td colspan='2'><hr noshade></td></tr>"; |
|
763 | + } |
|
706 | 764 | |
707 | - // displaying the categories and the forums |
|
708 | - if (!$forum and !$thread) |
|
709 | - { |
|
710 | - $sql = "SELECT * FROM ".$TBL_FORUMS." forums, ".$TBL_CATAGORIES." categories WHERE forums.cat_id=categories.cat_id ORDER BY forums.cat_id DESC"; |
|
711 | - $result = Database::query($sql); |
|
712 | - while ($myrow = Database::fetch_array($result)) |
|
713 | - { |
|
714 | - if ($myrow["cat_title"] !== $old_cat_title) |
|
715 | - { |
|
716 | - echo "<tr><td bgcolor='#4171B5' colspan='2'><font color='white'><b>".$myrow["cat_title"]."</b></font></td></tr>"; |
|
717 | - } |
|
718 | - $old_cat_title = $myrow["cat_title"]; |
|
719 | - echo "<tr><td><img src='../img/forum.gif'><a href='".api_get_self()."?content=Forum&category=".$myrow["cat_id"]."&forum=".$myrow["forum_id"]."&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".$myrow["forum_name"]."</td><td>"; |
|
720 | - showorhide_addresourcelink("Forum", $myrow["forum_id"]); |
|
721 | - echo "</td></tr>"; |
|
722 | - } |
|
723 | - } |
|
724 | - //displaying all the threads of one forum |
|
725 | - if ($forum) |
|
726 | - { |
|
727 | - // displaying the category title |
|
728 | - $sql = "SELECT * FROM ".$TBL_CATAGORIES." WHERE cat_id=$category"; |
|
729 | - $result = Database::query($sql); |
|
730 | - $myrow = Database::fetch_array($result); |
|
731 | - echo "<tr><td bgcolor='#4171B5' colspan='2'><font color='white'><b>".$myrow["cat_title"]."</b></font></td></tr>"; |
|
732 | - |
|
733 | - // displaying the forum title |
|
734 | - $sql = "SELECT * FROM ".$TBL_FORUMS." forums, ".$TBL_FORUMTOPICS." topics WHERE forums.forum_id=topics.forum_id"; |
|
735 | - $result = Database::query($sql); |
|
736 | - $myrow = Database::fetch_array($result); |
|
737 | - echo "<tr><td bgcolor='#cccccc' colspan='2'><b>".$myrow["forum_name"]."</b></td></tr>"; |
|
738 | - |
|
739 | - if (!$thread) |
|
740 | - { |
|
741 | - // displaying all the threads of this forum |
|
742 | - $sql = "SELECT * FROM ".$TBL_FORUMTOPICS." WHERE forum_id=$forum"; |
|
743 | - $result = Database::query($sql); |
|
744 | - while ($myrow = Database::fetch_array($result)) |
|
745 | - { |
|
746 | - echo "<tr><td><a href='".api_get_self()."?content=Forum&category=$category&forum=1&thread=".$myrow["topic_id"]."&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".$myrow["topic_title"]."</a> (".$myrow["prenom"]." ".$myrow["nom"].")</td><td>"; |
|
747 | - showorhide_addresourcelink("Thread", $myrow["topic_id"]); |
|
748 | - echo "</td></tr>"; |
|
749 | - } |
|
750 | - } |
|
751 | - else |
|
752 | - { |
|
753 | - // displaying all the replies |
|
754 | - $sql = "SELECT * FROM ".$tbl_posts." post, ".$tbl_posts_text." post_text WHERE post_text.post_id=post.post_id and post.topic_id=$thread ORDER BY post_text.post_id ASC"; |
|
755 | - $result = Database::query($sql); |
|
756 | - while ($myrow = Database::fetch_array($result)) |
|
757 | - { |
|
758 | - echo "<tr><td><b>".$myrow["post_title"]."</b><br>"; |
|
759 | - echo $myrow["post_text"]."</td>"; |
|
760 | - echo "<td>"; |
|
761 | - showorhide_addresourcelink("Post", $myrow["post_id"]); |
|
762 | - echo "</td></tr><tr><td colspan='2'><hr noshade></td></tr>"; |
|
763 | - } |
|
764 | - |
|
765 | - } |
|
766 | - } |
|
767 | - echo "</table>"; |
|
765 | + } |
|
766 | + } |
|
767 | + echo "</table>"; |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | /* |
@@ -774,57 +774,57 @@ discard block |
||
774 | 774 | */ |
775 | 775 | if ($content == "Link") |
776 | 776 | { |
777 | - // including the links language file |
|
778 | - include ("../lang/$language/link.inc.php"); |
|
779 | - |
|
780 | - $tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY); |
|
781 | - if (($learnpath_id != '') and ($content == 'Link')) |
|
782 | - { |
|
783 | - echo "<form name='learnpath_link'><table>"; |
|
784 | - echo "<tr></td><td align='left'>".get_lang('LinkTarget')." :</td><td align='left'><select name='target' onchange='targetfunc()'><option value='_self' "; |
|
785 | - if ($target == '_self') |
|
786 | - { |
|
787 | - echo "selected"; |
|
788 | - } |
|
789 | - echo ">".get_lang('SameWindow')."</option><option value='_blank'"; |
|
790 | - if ($target == '_blank') |
|
791 | - { |
|
792 | - echo "selected"; |
|
793 | - } |
|
794 | - echo ">".get_lang('NewWindow')."</option></select></td></tr></table></form>"; |
|
795 | - } |
|
796 | - |
|
797 | - // showing the links that are in the root (having no category) |
|
798 | - $sql = "SELECT * FROM ".$link_table." l, ".$item_property_table." ip WHERE (l.category_id=0 or l.category_id IS NULL) AND ip.tool = '".TOOL_LINK."' AND l.id=ip.ref AND ip.visibility='1'"; |
|
799 | - $result = Database::query($sql); |
|
800 | - if (Database::num_rows($result) > 0) |
|
801 | - { |
|
802 | - echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\"><i>".get_lang('NoCategory')."</i></td></tr></table>"; |
|
803 | - while ($myrow = Database::fetch_array($result)) |
|
804 | - { |
|
805 | - echo "<img src='../img/links.gif'>".$myrow["title"]; |
|
806 | - echo "<br>"; |
|
807 | - showorhide_addresourcelink($content, $myrow["id"]); |
|
808 | - echo "<br><br>"; |
|
809 | - } |
|
810 | - } |
|
811 | - |
|
812 | - // showing the categories and the links in it. |
|
813 | - $sqlcategories = "SELECT * FROM ".$tbl_categories." ORDER by display_order DESC"; |
|
814 | - $resultcategories = Database::query($sqlcategories) or die; |
|
815 | - while ($myrow = @ Database::fetch_array($resultcategories)) |
|
816 | - { |
|
817 | - $sql_links = "SELECT * FROM ".$link_table." l, ".$item_property_table." ip WHERE l.category_id='".$myrow["id"]."' AND ip.tool = '".TOOL_LINK."' AND l.id=ip.ref AND ip.visibility='1' ORDER BY l.display_order DESC"; |
|
818 | - echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\"><i>".$myrow["category_title"]."</i></td></tr></table>"; |
|
819 | - $result_links = Database::query($sql_links); |
|
820 | - while ($myrow = Database::fetch_array($result_links)) |
|
821 | - { |
|
822 | - echo "<img src='../img/links.gif' />".$myrow["title"]; |
|
823 | - echo "<br>"; |
|
824 | - showorhide_addresourcelink($content, $myrow["id"]); |
|
825 | - echo "<br><br>"; |
|
826 | - } |
|
827 | - } |
|
777 | + // including the links language file |
|
778 | + include ("../lang/$language/link.inc.php"); |
|
779 | + |
|
780 | + $tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY); |
|
781 | + if (($learnpath_id != '') and ($content == 'Link')) |
|
782 | + { |
|
783 | + echo "<form name='learnpath_link'><table>"; |
|
784 | + echo "<tr></td><td align='left'>".get_lang('LinkTarget')." :</td><td align='left'><select name='target' onchange='targetfunc()'><option value='_self' "; |
|
785 | + if ($target == '_self') |
|
786 | + { |
|
787 | + echo "selected"; |
|
788 | + } |
|
789 | + echo ">".get_lang('SameWindow')."</option><option value='_blank'"; |
|
790 | + if ($target == '_blank') |
|
791 | + { |
|
792 | + echo "selected"; |
|
793 | + } |
|
794 | + echo ">".get_lang('NewWindow')."</option></select></td></tr></table></form>"; |
|
795 | + } |
|
796 | + |
|
797 | + // showing the links that are in the root (having no category) |
|
798 | + $sql = "SELECT * FROM ".$link_table." l, ".$item_property_table." ip WHERE (l.category_id=0 or l.category_id IS NULL) AND ip.tool = '".TOOL_LINK."' AND l.id=ip.ref AND ip.visibility='1'"; |
|
799 | + $result = Database::query($sql); |
|
800 | + if (Database::num_rows($result) > 0) |
|
801 | + { |
|
802 | + echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\"><i>".get_lang('NoCategory')."</i></td></tr></table>"; |
|
803 | + while ($myrow = Database::fetch_array($result)) |
|
804 | + { |
|
805 | + echo "<img src='../img/links.gif'>".$myrow["title"]; |
|
806 | + echo "<br>"; |
|
807 | + showorhide_addresourcelink($content, $myrow["id"]); |
|
808 | + echo "<br><br>"; |
|
809 | + } |
|
810 | + } |
|
811 | + |
|
812 | + // showing the categories and the links in it. |
|
813 | + $sqlcategories = "SELECT * FROM ".$tbl_categories." ORDER by display_order DESC"; |
|
814 | + $resultcategories = Database::query($sqlcategories) or die; |
|
815 | + while ($myrow = @ Database::fetch_array($resultcategories)) |
|
816 | + { |
|
817 | + $sql_links = "SELECT * FROM ".$link_table." l, ".$item_property_table." ip WHERE l.category_id='".$myrow["id"]."' AND ip.tool = '".TOOL_LINK."' AND l.id=ip.ref AND ip.visibility='1' ORDER BY l.display_order DESC"; |
|
818 | + echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\"><i>".$myrow["category_title"]."</i></td></tr></table>"; |
|
819 | + $result_links = Database::query($sql_links); |
|
820 | + while ($myrow = Database::fetch_array($result_links)) |
|
821 | + { |
|
822 | + echo "<img src='../img/links.gif' />".$myrow["title"]; |
|
823 | + echo "<br>"; |
|
824 | + showorhide_addresourcelink($content, $myrow["id"]); |
|
825 | + echo "<br><br>"; |
|
826 | + } |
|
827 | + } |
|
828 | 828 | } |
829 | 829 | |
830 | 830 | /* |
@@ -834,31 +834,31 @@ discard block |
||
834 | 834 | */ |
835 | 835 | if (($content == "Exercise") or ($content == "HotPotatoes")) |
836 | 836 | { |
837 | - $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST); |
|
838 | - $result = Database::query("SELECT * FROM ".$TBL_EXERCICES." WHERE active='1' ORDER BY id ASC"); |
|
839 | - while ($myrow = Database::fetch_array($result)) |
|
840 | - { |
|
841 | - echo "<img src='../img/quiz.gif'>".$myrow["title"]."<br>"; |
|
842 | - showorhide_addresourcelink($content, $myrow["id"]); |
|
843 | - echo "<br><br>"; |
|
844 | - } |
|
837 | + $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST); |
|
838 | + $result = Database::query("SELECT * FROM ".$TBL_EXERCICES." WHERE active='1' ORDER BY id ASC"); |
|
839 | + while ($myrow = Database::fetch_array($result)) |
|
840 | + { |
|
841 | + echo "<img src='../img/quiz.gif'>".$myrow["title"]."<br>"; |
|
842 | + showorhide_addresourcelink($content, $myrow["id"]); |
|
843 | + echo "<br><br>"; |
|
844 | + } |
|
845 | + |
|
846 | + if ($from_learnpath == 'yes') |
|
847 | + { |
|
848 | + $uploadPath = "/HotPotatoes_files"; |
|
849 | + $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT); |
|
850 | + $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'; |
|
851 | + $sql = "SELECT * FROM ".$TBL_DOCUMENT." WHERE (path LIKE '%htm%' OR path LIKE '%html%') AND path LIKE '".$uploadPath."/%/%' ORDER BY id ASC"; |
|
852 | + $result = Database::query($sql); |
|
853 | + while ($myrow = Database::fetch_array($result)) |
|
854 | + { |
|
855 | + $path = $myrow["path"]; |
|
856 | + echo "<img src='../img/jqz.gif'>".GetQuizName($path, $documentPath)."<br>"; |
|
857 | + showorhide_addresourcelink("HotPotatoes", $myrow["id"]); |
|
858 | + echo "<br><br>"; |
|
845 | 859 | |
846 | - if ($from_learnpath == 'yes') |
|
847 | - { |
|
848 | - $uploadPath = "/HotPotatoes_files"; |
|
849 | - $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT); |
|
850 | - $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'; |
|
851 | - $sql = "SELECT * FROM ".$TBL_DOCUMENT." WHERE (path LIKE '%htm%' OR path LIKE '%html%') AND path LIKE '".$uploadPath."/%/%' ORDER BY id ASC"; |
|
852 | - $result = Database::query($sql); |
|
853 | - while ($myrow = Database::fetch_array($result)) |
|
854 | - { |
|
855 | - $path = $myrow["path"]; |
|
856 | - echo "<img src='../img/jqz.gif'>".GetQuizName($path, $documentPath)."<br>"; |
|
857 | - showorhide_addresourcelink("HotPotatoes", $myrow["id"]); |
|
858 | - echo "<br><br>"; |
|
859 | - |
|
860 | - } |
|
861 | - } |
|
860 | + } |
|
861 | + } |
|
862 | 862 | } |
863 | 863 | |
864 | 864 | /* |
@@ -876,10 +876,10 @@ discard block |
||
876 | 876 | <td align="left"><input name="external_link" type="text" id="external_link" value="http://"></td> |
877 | 877 | <?php |
878 | 878 | |
879 | - if ($learnpath_id != '') |
|
880 | - { |
|
881 | - echo "</tr><tr><td align='right'>".get_lang('LinkTarget')." :</td><td align='left'><select name='target'><option value='_self'>".get_lang('SameWindow')."</option><option value='_blank'>".get_lang('NewWindow')."</option></select></td>"; |
|
882 | - } |
|
879 | + if ($learnpath_id != '') |
|
880 | + { |
|
881 | + echo "</tr><tr><td align='right'>".get_lang('LinkTarget')." :</td><td align='left'><select name='target'><option value='_self'>".get_lang('SameWindow')."</option><option value='_blank'>".get_lang('NewWindow')."</option></select></td>"; |
|
882 | + } |
|
883 | 883 | ?> |
884 | 884 | </tr> |
885 | 885 | <tr> |
@@ -891,14 +891,14 @@ discard block |
||
891 | 891 | <option value="0"><?php echo get_lang('MainCategory'); ?></option> |
892 | 892 | <?php |
893 | 893 | |
894 | - $tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY); |
|
895 | - $sql = "SELECT * FROM $tbl_categories ORDER BY display_order ASC"; |
|
896 | - echo $sql; |
|
897 | - $result = Database::query($sql); |
|
898 | - while ($row = Database::fetch_array($result)) |
|
899 | - { |
|
900 | - echo "<option value='".$row["id"]."'>".$row["category_title"]."</option>"; |
|
901 | - } |
|
894 | + $tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY); |
|
895 | + $sql = "SELECT * FROM $tbl_categories ORDER BY display_order ASC"; |
|
896 | + echo $sql; |
|
897 | + $result = Database::query($sql); |
|
898 | + while ($row = Database::fetch_array($result)) |
|
899 | + { |
|
900 | + echo "<option value='".$row["id"]."'>".$row["category_title"]."</option>"; |
|
901 | + } |
|
902 | 902 | ?> |
903 | 903 | |
904 | 904 | </select><?php } ?></td> |
@@ -927,7 +927,7 @@ discard block |
||
927 | 927 | */ |
928 | 928 | if ($content == "Assignment") |
929 | 929 | { |
930 | - echo "<a href=".api_get_self()."?content=Ass&add=Ass&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no>".get_lang('AddAssignmentPage')."</a>"; |
|
930 | + echo "<a href=".api_get_self()."?content=Ass&add=Ass&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no>".get_lang('AddAssignmentPage')."</a>"; |
|
931 | 931 | } |
932 | 932 | |
933 | 933 | /* |
@@ -937,7 +937,7 @@ discard block |
||
937 | 937 | */ |
938 | 938 | if ($content == "Dropbox") |
939 | 939 | { |
940 | - echo "<a href='".api_get_self()."?content=Drop&add=Drop&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('DropboxAdd')."</a>"; |
|
940 | + echo "<a href='".api_get_self()."?content=Drop&add=Drop&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('DropboxAdd')."</a>"; |
|
941 | 941 | } |
942 | 942 | |
943 | 943 | /* |
@@ -947,7 +947,7 @@ discard block |
||
947 | 947 | */ |
948 | 948 | if ($content == "Introduction_text") |
949 | 949 | { |
950 | - echo "<a href='".api_get_self()."?content=Intro&add=Intro&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('IntroductionTextAdd')."</a>"; |
|
950 | + echo "<a href='".api_get_self()."?content=Intro&add=Intro&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('IntroductionTextAdd')."</a>"; |
|
951 | 951 | } |
952 | 952 | |
953 | 953 | /* |
@@ -957,7 +957,7 @@ discard block |
||
957 | 957 | */ |
958 | 958 | if ($content == "Course_description") |
959 | 959 | { |
960 | - echo "<a href='".api_get_self()."?content=Course_desc&add=Course_desc&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('CourseDescriptionAdd')."</a>"; |
|
960 | + echo "<a href='".api_get_self()."?content=Course_desc&add=Course_desc&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('CourseDescriptionAdd')."</a>"; |
|
961 | 961 | } |
962 | 962 | |
963 | 963 | /* |
@@ -967,7 +967,7 @@ discard block |
||
967 | 967 | */ |
968 | 968 | if ($content == "Groups") |
969 | 969 | { |
970 | - echo "<a href='".api_get_self()."?content=Group&add=Group&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('$GroupsAdd')."</a>"; |
|
970 | + echo "<a href='".api_get_self()."?content=Group&add=Group&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('$GroupsAdd')."</a>"; |
|
971 | 971 | } |
972 | 972 | |
973 | 973 | /* |
@@ -977,13 +977,13 @@ discard block |
||
977 | 977 | */ |
978 | 978 | if ($content == "Users") |
979 | 979 | { |
980 | - echo "<a href='".api_get_self()."?content=User&add=User&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('UsersAdd')."</a>"; |
|
980 | + echo "<a href='".api_get_self()."?content=User&add=User&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('UsersAdd')."</a>"; |
|
981 | 981 | } |
982 | 982 | |
983 | 983 | if ($showresources) |
984 | 984 | { |
985 | - //echo "<h4>".get_lang('ResourceAdded')."</h4>"; |
|
986 | - display_resources(1); |
|
985 | + //echo "<h4>".get_lang('ResourceAdded')."</h4>"; |
|
986 | + display_resources(1); |
|
987 | 987 | } |
988 | 988 | |
989 | 989 | echo "</td></tr></table>"; |
@@ -10,521 +10,521 @@ |
||
10 | 10 | */ |
11 | 11 | class WSCMCourse extends WSCM |
12 | 12 | { |
13 | - /** |
|
14 | - * Deletes a course (helper method) |
|
15 | - * |
|
16 | - * @param string Course id field name |
|
17 | - * @param string Course id value |
|
18 | - * @return mixed True if the course was successfully deleted, WSError otherwise |
|
19 | - */ |
|
20 | - protected function deleteCourseHelper($course_id_field_name, $course_id_value) { |
|
21 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
22 | - if($course_id instanceof WSCMError) { |
|
23 | - return $course_id; |
|
24 | - } else { |
|
25 | - $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
26 | - CourseManager::delete_course($course_code); |
|
27 | - return true; |
|
28 | - } |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * Deletes a course |
|
33 | - * |
|
34 | - * @param string API secret key |
|
35 | - * @param string Course id field name |
|
36 | - * @param string Course id value |
|
37 | - */ |
|
38 | - public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) { |
|
39 | - $verifKey = $this->verifyKey($secret_key); |
|
40 | - if($verifKey instanceof WSError) { |
|
41 | - $this->handleError($verifKey); |
|
42 | - } else { |
|
43 | - $result = $this->deleteCourseHelper($course_id_field_name, $course_id_value); |
|
44 | - if($result instanceof WSError) { |
|
45 | - $this->handleError($result); |
|
46 | - } |
|
47 | - } |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Deletes multiple courses |
|
52 | - * |
|
53 | - * @param string API secret key |
|
54 | - * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value') |
|
55 | - * @return array Array with elements like array('course_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). Note that if the result array contains a code different |
|
56 | - * than 0, an error occured |
|
57 | - */ |
|
58 | - public function DeleteCourses($secret_key, $courses) { |
|
59 | - $verifKey = $this->verifyKey($secret_key); |
|
60 | - if($verifKey instanceof WSError) { |
|
61 | - $this->handleError($verifKey); |
|
62 | - } else { |
|
63 | - $results = array(); |
|
64 | - foreach($courses as $course) { |
|
65 | - $result_tmp = array(); |
|
66 | - $result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']); |
|
67 | - $result_tmp['course_id_value'] = $course['course_id_value']; |
|
68 | - if($result_op instanceof WSCMError) { |
|
69 | - // Return the error in the results |
|
70 | - $result_tmp['result'] = $result_op->toArray(); |
|
71 | - } else { |
|
72 | - $result_tmp['result'] = $this->getSuccessfulResult(); |
|
73 | - } |
|
74 | - $results[] = $result_tmp; |
|
75 | - } |
|
76 | - return $results; |
|
77 | - } |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Creates a course (helper method) |
|
82 | - * |
|
83 | - * @param string Title |
|
84 | - * @param string Category code |
|
85 | - * @param string Wanted code. If it's not defined, it will be generated automatically |
|
86 | - * @param string Tutor name |
|
87 | - * @param string Course admin user id field name |
|
88 | - * @param string Course admin user id value |
|
89 | - * @param string Course language |
|
90 | - * @param string Course id field name |
|
91 | - * @param string Course id value |
|
92 | - * @param array Course extra fields |
|
93 | - * @return mixed Generated id if creation was successful, WSError otherwise |
|
94 | - */ |
|
95 | - protected function createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) { |
|
96 | - // Add the original course id field name and value to the extra fields if needed |
|
97 | - $extras_associative = array(); |
|
98 | - if($course_id_field_name != "chamilo_course_id") { |
|
99 | - $extras_associative[$course_id_field_name] = $course_id_value; |
|
100 | - } |
|
101 | - foreach($extras as $extra) { |
|
102 | - $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
103 | - } |
|
104 | - $course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value); |
|
105 | - if($course_admin_id instanceof WSError) { |
|
106 | - return $course_admin_id; |
|
107 | - } |
|
108 | - if($wanted_code == '') { |
|
109 | - $wanted_code = CourseManager::generate_course_code($title); |
|
110 | - } |
|
111 | - $result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0); |
|
112 | - if (!$result) { |
|
113 | - return new WSError(202, 'There was an error creating the course'); |
|
114 | - } else { |
|
115 | - // Update extra fields |
|
116 | - foreach($extras_associative as $fname => $fvalue) { |
|
117 | - CourseManager::update_course_extra_field_value($result, $fname, $fvalue); |
|
118 | - } |
|
119 | - // Get course id |
|
120 | - $course_info = CourseManager::get_course_information($result); |
|
121 | - return $course_info['real_id']; |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Creates a course |
|
127 | - * |
|
128 | - * @param string API secret key |
|
129 | - * @param string Title |
|
130 | - * @param string Category code |
|
131 | - * @param string Wanted code. If it's not defined, it will be generated automatically |
|
132 | - * @param string Tutor name |
|
133 | - * @param string Course admin user id field name |
|
134 | - * @param string Course admin user id value |
|
135 | - * @param string Course language |
|
136 | - * @param string Course id field name |
|
137 | - * @param string Course id value |
|
138 | - * @param array Course extra fields |
|
139 | - * @return int Course id generated |
|
140 | - */ |
|
141 | - public function CreateCourse($secret_key, $title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) { |
|
142 | - // First, verify the secret key |
|
143 | - $verifKey = $this->verifyKey($secret_key); |
|
144 | - if($verifKey instanceof WSError) { |
|
145 | - $this->handleError($verifKey); |
|
146 | - } else { |
|
147 | - $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras); |
|
148 | - if($result instanceof WSError) { |
|
149 | - $this->handleError($result); |
|
150 | - } else { |
|
151 | - return $result; |
|
152 | - } |
|
153 | - } |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Create multiple courses |
|
158 | - * |
|
159 | - * @param string API secret key |
|
160 | - * @param array Courses to be created, with elements following the structure presented in CreateCourse |
|
161 | - * @return array Array with elements of the form array('course_id_value' => 'original value sent', 'course_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful')) |
|
162 | - */ |
|
163 | - public function CreateCourses($secret_key, $courses) { |
|
164 | - // First, verify the secret key |
|
165 | - $verifKey = $this->verifyKey($secret_key); |
|
166 | - if($verifKey instanceof WSCMError) { |
|
167 | - $this->handleError($verifKey); |
|
168 | - } else { |
|
169 | - $results = array(); |
|
170 | - foreach($courses as $course) { |
|
171 | - $result_tmp = array(); |
|
172 | - //reinitialize variables just in case |
|
173 | - $title = $category_code = $wanted_code = $tutor_name = $course_admin_user_id_field_name = $course_admin_user_id_value = $language = $course_id_field_name = $course_id_value = $extras = null; |
|
174 | - extract($course); |
|
175 | - $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras); |
|
176 | - if($result instanceof WSCMError) { |
|
177 | - $result_tmp['result'] = $result->toArray(); |
|
178 | - $result_tmp['course_id_value'] = $course_id_value; |
|
179 | - $result_tmp['course_id_generated'] = 0; |
|
180 | - } else { |
|
181 | - $result_tmp['result'] = $this->getSuccessfulResult(); |
|
182 | - $result_tmp['course_id_value'] = $course_id_value; |
|
183 | - $result_tmp['course_id_generated'] = $result; |
|
184 | - } |
|
185 | - $results[] = $result_tmp; |
|
186 | - } |
|
187 | - return $results; |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Edits a course (helper method) |
|
193 | - * |
|
194 | - * @param string Course id field name |
|
195 | - * @param string Course id value |
|
196 | - * @param string Title |
|
197 | - * @param string Category code |
|
198 | - * @param string Department name |
|
199 | - * @param string Department url |
|
200 | - * @param string Course language |
|
201 | - * @param int Visibility |
|
202 | - * @param int Subscribe (0 = denied, 1 = allowed) |
|
203 | - * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
204 | - * @param string Visual code |
|
205 | - * @param array Course extra fields |
|
206 | - * @return mixed True in case of success, WSError otherwise |
|
207 | - */ |
|
208 | - protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
|
209 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
210 | - if($course_id instanceof WSCMError) { |
|
211 | - return $course_id; |
|
212 | - } else { |
|
213 | - $attributes = array(); |
|
214 | - if(!empty($title)) { |
|
215 | - $attributes['title'] = $title; |
|
216 | - } |
|
217 | - if(!empty($category_code)) { |
|
218 | - $attributes['category_code'] = $category_code; |
|
219 | - } |
|
220 | - if(!empty($department_name)) { |
|
221 | - $attributes['department_name'] = $department_name; |
|
222 | - } |
|
223 | - if(!empty($department_url)) { |
|
224 | - $attributes['department_url'] = $department_url; |
|
225 | - } |
|
226 | - if(!empty($language)) { |
|
227 | - $attributes['course_language'] = $language; |
|
228 | - } |
|
229 | - if($visibility != '') { |
|
230 | - $attributes['visibility'] = (int)$visibility; |
|
231 | - } |
|
232 | - if($subscribe != '') { |
|
233 | - $attributes['subscribe'] = (int)$subscribe; |
|
234 | - } |
|
235 | - if($unsubscribe != '') { |
|
236 | - $attributes['unsubscribe'] = (int)$unsubscribe; |
|
237 | - } |
|
238 | - if(!empty($visual_code)) { |
|
239 | - $attributes['visual_code'] = $visual_code; |
|
240 | - } |
|
241 | - if(!empty($attributes)) { |
|
242 | - CourseManager::update_attributes($course_id, $attributes); |
|
243 | - } |
|
244 | - if(!empty($extras)) { |
|
245 | - $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
246 | - $extras_associative = array(); |
|
247 | - foreach($extras as $extra) { |
|
248 | - $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
249 | - } |
|
250 | - foreach($extras_associative as $fname => $fvalue) { |
|
251 | - CourseManager::update_extra_field_value($course_code, $fname, $fvalue); |
|
252 | - } |
|
253 | - } |
|
254 | - return true; |
|
255 | - } |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Edits a course |
|
260 | - * |
|
261 | - * @param string API secret key |
|
262 | - * @param string Course id field name |
|
263 | - * @param string Course id value |
|
264 | - * @param string Title |
|
265 | - * @param string Category code |
|
266 | - * @param string Department name |
|
267 | - * @param string Department url |
|
268 | - * @param string Course language |
|
269 | - * @param int Visibility |
|
270 | - * @param int Subscribe (0 = denied, 1 = allowed) |
|
271 | - * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
272 | - * @param string Visual code |
|
273 | - * @param array Course extra fields |
|
274 | - */ |
|
275 | - public function EditCourse($secret_key, $course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
|
276 | - $verifKey = $this->verifyKey($secret_key); |
|
277 | - if($verifKey instanceof WSCMError) { |
|
278 | - $this->handleError($verifKey); |
|
279 | - } else { |
|
280 | - $result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras); |
|
281 | - if($result instanceof WSCMError) { |
|
282 | - $this->handleError($result); |
|
283 | - } |
|
284 | - } |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * List courses |
|
289 | - * |
|
290 | - * @param string API secret key |
|
291 | - * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
292 | - * @return array An array with elements of the form ('id' => 'Course internal id', 'code' => 'Course code', 'title' => 'Course title', 'language' => 'Course language', 'visibility' => 'Course visibility', |
|
293 | - * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id') |
|
294 | - */ |
|
295 | - public function ListCourses($secret_key, $course_id_field_name) { |
|
296 | - $verifKey = $this->verifyKey($secret_key); |
|
297 | - if($verifKey instanceof WSError) { |
|
298 | - $this->handleError($verifKey); |
|
299 | - } else { |
|
300 | - $courses_result = array(); |
|
301 | - $category_names = array(); |
|
302 | - |
|
303 | - $courses = CourseManager::get_courses_list(); |
|
304 | - foreach($courses as $course) { |
|
305 | - $course_tmp = array(); |
|
306 | - $course_tmp['id'] = $course['id']; |
|
307 | - $course_tmp['code'] = $course['code']; |
|
308 | - $course_tmp['title'] = $course['title']; |
|
309 | - $course_tmp['language'] = $course['course_language']; |
|
310 | - $course_tmp['visibility'] = $course['visibility']; |
|
311 | - |
|
312 | - // Determining category name |
|
313 | - if($category_names[$course['category_code']]) { |
|
314 | - $course_tmp['category_name'] = $category_names[$course['category_code']]; |
|
315 | - } else { |
|
316 | - $category = CourseManager::get_course_category($course['category_code']); |
|
317 | - $category_names[$course['category_code']] = $category['name']; |
|
318 | - $course_tmp['category_name'] = $category['name']; |
|
319 | - } |
|
320 | - |
|
321 | - // Determining number of students registered in course |
|
322 | - $user_list = CourseManager::get_user_list_from_course_code($course['code']); |
|
323 | - $course_tmp['number_students'] = count($user_list); |
|
324 | - |
|
325 | - // Determining external course id |
|
326 | - $course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_id_field_name, $course['code']); |
|
327 | - |
|
328 | - |
|
329 | - $courses_result[] = $course_tmp; |
|
330 | - } |
|
331 | - |
|
332 | - return $courses_result; |
|
333 | - } |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * Subscribe or unsubscribe user to a course (helper method) |
|
338 | - * |
|
339 | - * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
340 | - * @param string Course id value. |
|
341 | - * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
342 | - * @param string User id value |
|
343 | - * @param int Set to 1 to subscribe, 0 to unsubscribe |
|
344 | - * @param int Status (STUDENT or TEACHER) Used for subscription only |
|
345 | - * @return mixed True if subscription or unsubscription was successful, false otherwise |
|
346 | - */ |
|
347 | - protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) { |
|
348 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
349 | - if($course_id instanceof WSError) { |
|
350 | - return $course_id; |
|
351 | - } else { |
|
352 | - $user_id = $this->getUserId($user_id_field_name, $user_id_value); |
|
353 | - if($user_id instanceof WSError) { |
|
354 | - return $user_id; |
|
355 | - } else { |
|
356 | - $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
357 | - if($state == 0) { |
|
358 | - // Unsubscribe user |
|
359 | - CourseManager::unsubscribe_user($user_id, $course_code); |
|
360 | - return true; |
|
361 | - } else { |
|
362 | - // Subscribe user |
|
363 | - if(CourseManager::subscribe_user($user_id, $course_code, $status)) { |
|
364 | - return true; |
|
365 | - } else { |
|
366 | - return new WSError(203, 'An error occured subscribing to this course'); |
|
367 | - } |
|
368 | - } |
|
369 | - } |
|
370 | - } |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * Subscribe user to a course |
|
375 | - * |
|
376 | - * @param string API secret key |
|
377 | - * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
378 | - * @param string Course id value. |
|
379 | - * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
380 | - * @param string User id value |
|
381 | - * @param int Status (1 = Teacher, 5 = Student) |
|
382 | - */ |
|
383 | - public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) { |
|
384 | - $verifKey = $this->verifyKey($secret_key); |
|
385 | - if($verifKey instanceof WSError) { |
|
386 | - $this->handleError($verifKey); |
|
387 | - } else { |
|
388 | - $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status); |
|
389 | - if($result instanceof WSError) { |
|
390 | - $this->handleError($result); |
|
391 | - } |
|
392 | - } |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Unsusbscribe user from course |
|
397 | - * |
|
398 | - * @param string API secret key |
|
399 | - * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
400 | - * @param string Course id value. |
|
401 | - * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
402 | - * @param string User id value |
|
403 | - */ |
|
404 | - public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) { |
|
405 | - $verifKey = $this->verifyKey($secret_key); |
|
406 | - if($verifKey instanceof WSError) { |
|
407 | - $this->handleError($verifKey); |
|
408 | - } else { |
|
409 | - $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0); |
|
410 | - if($result instanceof WSError) { |
|
411 | - $this->handleError($result); |
|
412 | - } |
|
413 | - } |
|
414 | - } |
|
415 | - |
|
416 | - /** |
|
417 | - * Returns the descriptions of a course, along with their id |
|
418 | - * |
|
419 | - * @param string API secret key |
|
420 | - * @param string Course id field name |
|
421 | - * @param string Course id value |
|
422 | - * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content') |
|
423 | - */ |
|
424 | - public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) { |
|
425 | - $verifKey = $this->verifyKey($secret_key); |
|
426 | - if($verifKey instanceof WSError) { |
|
427 | - $this->handleError($verifKey); |
|
428 | - } else { |
|
429 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
430 | - if($course_id instanceof WSError) { |
|
431 | - return $course_id; |
|
432 | - } else { |
|
433 | - // Course exists, get its descriptions |
|
434 | - $descriptions = CourseDescription::get_descriptions($course_id); |
|
435 | - $results = array(); |
|
436 | - foreach($descriptions as $description) { |
|
437 | - $results[] = array('course_desc_id' => $description->get_description_type(), |
|
438 | - 'course_desc_title' => $description->get_title(), |
|
439 | - 'course_desc_content' => $description->get_content()); |
|
440 | - } |
|
441 | - return $results; |
|
442 | - } |
|
443 | - } |
|
444 | - } |
|
445 | - |
|
446 | - |
|
447 | - /** |
|
448 | - * Edit course description |
|
449 | - * |
|
450 | - * @param string API secret key |
|
451 | - * @param string Course id field name |
|
452 | - * @param string Course id value |
|
453 | - * @param int Category id from course description |
|
454 | - * @param string Description title |
|
455 | - * @param string Course description content |
|
456 | - */ |
|
457 | - public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) { |
|
458 | - $verifKey = $this->verifyKey($secret_key); |
|
459 | - if($verifKey instanceof WSError) { |
|
460 | - $this->handleError($verifKey); |
|
461 | - } else { |
|
462 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
463 | - if($course_id instanceof WSError) { |
|
464 | - return $course_id; |
|
465 | - } else { |
|
466 | - // Create the new course description |
|
467 | - $cd = new CourseDescription(); |
|
468 | - $cd->set_description_type($course_desc_id); |
|
469 | - $cd->set_title($course_desc_title); |
|
470 | - $cd->set_content($course_desc_content); |
|
471 | - $cd->set_session_id(0); |
|
472 | - |
|
473 | - // Get course info |
|
13 | + /** |
|
14 | + * Deletes a course (helper method) |
|
15 | + * |
|
16 | + * @param string Course id field name |
|
17 | + * @param string Course id value |
|
18 | + * @return mixed True if the course was successfully deleted, WSError otherwise |
|
19 | + */ |
|
20 | + protected function deleteCourseHelper($course_id_field_name, $course_id_value) { |
|
21 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
22 | + if($course_id instanceof WSCMError) { |
|
23 | + return $course_id; |
|
24 | + } else { |
|
25 | + $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
26 | + CourseManager::delete_course($course_code); |
|
27 | + return true; |
|
28 | + } |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * Deletes a course |
|
33 | + * |
|
34 | + * @param string API secret key |
|
35 | + * @param string Course id field name |
|
36 | + * @param string Course id value |
|
37 | + */ |
|
38 | + public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) { |
|
39 | + $verifKey = $this->verifyKey($secret_key); |
|
40 | + if($verifKey instanceof WSError) { |
|
41 | + $this->handleError($verifKey); |
|
42 | + } else { |
|
43 | + $result = $this->deleteCourseHelper($course_id_field_name, $course_id_value); |
|
44 | + if($result instanceof WSError) { |
|
45 | + $this->handleError($result); |
|
46 | + } |
|
47 | + } |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Deletes multiple courses |
|
52 | + * |
|
53 | + * @param string API secret key |
|
54 | + * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value') |
|
55 | + * @return array Array with elements like array('course_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). Note that if the result array contains a code different |
|
56 | + * than 0, an error occured |
|
57 | + */ |
|
58 | + public function DeleteCourses($secret_key, $courses) { |
|
59 | + $verifKey = $this->verifyKey($secret_key); |
|
60 | + if($verifKey instanceof WSError) { |
|
61 | + $this->handleError($verifKey); |
|
62 | + } else { |
|
63 | + $results = array(); |
|
64 | + foreach($courses as $course) { |
|
65 | + $result_tmp = array(); |
|
66 | + $result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']); |
|
67 | + $result_tmp['course_id_value'] = $course['course_id_value']; |
|
68 | + if($result_op instanceof WSCMError) { |
|
69 | + // Return the error in the results |
|
70 | + $result_tmp['result'] = $result_op->toArray(); |
|
71 | + } else { |
|
72 | + $result_tmp['result'] = $this->getSuccessfulResult(); |
|
73 | + } |
|
74 | + $results[] = $result_tmp; |
|
75 | + } |
|
76 | + return $results; |
|
77 | + } |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Creates a course (helper method) |
|
82 | + * |
|
83 | + * @param string Title |
|
84 | + * @param string Category code |
|
85 | + * @param string Wanted code. If it's not defined, it will be generated automatically |
|
86 | + * @param string Tutor name |
|
87 | + * @param string Course admin user id field name |
|
88 | + * @param string Course admin user id value |
|
89 | + * @param string Course language |
|
90 | + * @param string Course id field name |
|
91 | + * @param string Course id value |
|
92 | + * @param array Course extra fields |
|
93 | + * @return mixed Generated id if creation was successful, WSError otherwise |
|
94 | + */ |
|
95 | + protected function createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) { |
|
96 | + // Add the original course id field name and value to the extra fields if needed |
|
97 | + $extras_associative = array(); |
|
98 | + if($course_id_field_name != "chamilo_course_id") { |
|
99 | + $extras_associative[$course_id_field_name] = $course_id_value; |
|
100 | + } |
|
101 | + foreach($extras as $extra) { |
|
102 | + $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
103 | + } |
|
104 | + $course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value); |
|
105 | + if($course_admin_id instanceof WSError) { |
|
106 | + return $course_admin_id; |
|
107 | + } |
|
108 | + if($wanted_code == '') { |
|
109 | + $wanted_code = CourseManager::generate_course_code($title); |
|
110 | + } |
|
111 | + $result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0); |
|
112 | + if (!$result) { |
|
113 | + return new WSError(202, 'There was an error creating the course'); |
|
114 | + } else { |
|
115 | + // Update extra fields |
|
116 | + foreach($extras_associative as $fname => $fvalue) { |
|
117 | + CourseManager::update_course_extra_field_value($result, $fname, $fvalue); |
|
118 | + } |
|
119 | + // Get course id |
|
120 | + $course_info = CourseManager::get_course_information($result); |
|
121 | + return $course_info['real_id']; |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Creates a course |
|
127 | + * |
|
128 | + * @param string API secret key |
|
129 | + * @param string Title |
|
130 | + * @param string Category code |
|
131 | + * @param string Wanted code. If it's not defined, it will be generated automatically |
|
132 | + * @param string Tutor name |
|
133 | + * @param string Course admin user id field name |
|
134 | + * @param string Course admin user id value |
|
135 | + * @param string Course language |
|
136 | + * @param string Course id field name |
|
137 | + * @param string Course id value |
|
138 | + * @param array Course extra fields |
|
139 | + * @return int Course id generated |
|
140 | + */ |
|
141 | + public function CreateCourse($secret_key, $title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) { |
|
142 | + // First, verify the secret key |
|
143 | + $verifKey = $this->verifyKey($secret_key); |
|
144 | + if($verifKey instanceof WSError) { |
|
145 | + $this->handleError($verifKey); |
|
146 | + } else { |
|
147 | + $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras); |
|
148 | + if($result instanceof WSError) { |
|
149 | + $this->handleError($result); |
|
150 | + } else { |
|
151 | + return $result; |
|
152 | + } |
|
153 | + } |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Create multiple courses |
|
158 | + * |
|
159 | + * @param string API secret key |
|
160 | + * @param array Courses to be created, with elements following the structure presented in CreateCourse |
|
161 | + * @return array Array with elements of the form array('course_id_value' => 'original value sent', 'course_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful')) |
|
162 | + */ |
|
163 | + public function CreateCourses($secret_key, $courses) { |
|
164 | + // First, verify the secret key |
|
165 | + $verifKey = $this->verifyKey($secret_key); |
|
166 | + if($verifKey instanceof WSCMError) { |
|
167 | + $this->handleError($verifKey); |
|
168 | + } else { |
|
169 | + $results = array(); |
|
170 | + foreach($courses as $course) { |
|
171 | + $result_tmp = array(); |
|
172 | + //reinitialize variables just in case |
|
173 | + $title = $category_code = $wanted_code = $tutor_name = $course_admin_user_id_field_name = $course_admin_user_id_value = $language = $course_id_field_name = $course_id_value = $extras = null; |
|
174 | + extract($course); |
|
175 | + $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras); |
|
176 | + if($result instanceof WSCMError) { |
|
177 | + $result_tmp['result'] = $result->toArray(); |
|
178 | + $result_tmp['course_id_value'] = $course_id_value; |
|
179 | + $result_tmp['course_id_generated'] = 0; |
|
180 | + } else { |
|
181 | + $result_tmp['result'] = $this->getSuccessfulResult(); |
|
182 | + $result_tmp['course_id_value'] = $course_id_value; |
|
183 | + $result_tmp['course_id_generated'] = $result; |
|
184 | + } |
|
185 | + $results[] = $result_tmp; |
|
186 | + } |
|
187 | + return $results; |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Edits a course (helper method) |
|
193 | + * |
|
194 | + * @param string Course id field name |
|
195 | + * @param string Course id value |
|
196 | + * @param string Title |
|
197 | + * @param string Category code |
|
198 | + * @param string Department name |
|
199 | + * @param string Department url |
|
200 | + * @param string Course language |
|
201 | + * @param int Visibility |
|
202 | + * @param int Subscribe (0 = denied, 1 = allowed) |
|
203 | + * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
204 | + * @param string Visual code |
|
205 | + * @param array Course extra fields |
|
206 | + * @return mixed True in case of success, WSError otherwise |
|
207 | + */ |
|
208 | + protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
|
209 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
210 | + if($course_id instanceof WSCMError) { |
|
211 | + return $course_id; |
|
212 | + } else { |
|
213 | + $attributes = array(); |
|
214 | + if(!empty($title)) { |
|
215 | + $attributes['title'] = $title; |
|
216 | + } |
|
217 | + if(!empty($category_code)) { |
|
218 | + $attributes['category_code'] = $category_code; |
|
219 | + } |
|
220 | + if(!empty($department_name)) { |
|
221 | + $attributes['department_name'] = $department_name; |
|
222 | + } |
|
223 | + if(!empty($department_url)) { |
|
224 | + $attributes['department_url'] = $department_url; |
|
225 | + } |
|
226 | + if(!empty($language)) { |
|
227 | + $attributes['course_language'] = $language; |
|
228 | + } |
|
229 | + if($visibility != '') { |
|
230 | + $attributes['visibility'] = (int)$visibility; |
|
231 | + } |
|
232 | + if($subscribe != '') { |
|
233 | + $attributes['subscribe'] = (int)$subscribe; |
|
234 | + } |
|
235 | + if($unsubscribe != '') { |
|
236 | + $attributes['unsubscribe'] = (int)$unsubscribe; |
|
237 | + } |
|
238 | + if(!empty($visual_code)) { |
|
239 | + $attributes['visual_code'] = $visual_code; |
|
240 | + } |
|
241 | + if(!empty($attributes)) { |
|
242 | + CourseManager::update_attributes($course_id, $attributes); |
|
243 | + } |
|
244 | + if(!empty($extras)) { |
|
245 | + $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
246 | + $extras_associative = array(); |
|
247 | + foreach($extras as $extra) { |
|
248 | + $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
249 | + } |
|
250 | + foreach($extras_associative as $fname => $fvalue) { |
|
251 | + CourseManager::update_extra_field_value($course_code, $fname, $fvalue); |
|
252 | + } |
|
253 | + } |
|
254 | + return true; |
|
255 | + } |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Edits a course |
|
260 | + * |
|
261 | + * @param string API secret key |
|
262 | + * @param string Course id field name |
|
263 | + * @param string Course id value |
|
264 | + * @param string Title |
|
265 | + * @param string Category code |
|
266 | + * @param string Department name |
|
267 | + * @param string Department url |
|
268 | + * @param string Course language |
|
269 | + * @param int Visibility |
|
270 | + * @param int Subscribe (0 = denied, 1 = allowed) |
|
271 | + * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
272 | + * @param string Visual code |
|
273 | + * @param array Course extra fields |
|
274 | + */ |
|
275 | + public function EditCourse($secret_key, $course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
|
276 | + $verifKey = $this->verifyKey($secret_key); |
|
277 | + if($verifKey instanceof WSCMError) { |
|
278 | + $this->handleError($verifKey); |
|
279 | + } else { |
|
280 | + $result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras); |
|
281 | + if($result instanceof WSCMError) { |
|
282 | + $this->handleError($result); |
|
283 | + } |
|
284 | + } |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * List courses |
|
289 | + * |
|
290 | + * @param string API secret key |
|
291 | + * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
292 | + * @return array An array with elements of the form ('id' => 'Course internal id', 'code' => 'Course code', 'title' => 'Course title', 'language' => 'Course language', 'visibility' => 'Course visibility', |
|
293 | + * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id') |
|
294 | + */ |
|
295 | + public function ListCourses($secret_key, $course_id_field_name) { |
|
296 | + $verifKey = $this->verifyKey($secret_key); |
|
297 | + if($verifKey instanceof WSError) { |
|
298 | + $this->handleError($verifKey); |
|
299 | + } else { |
|
300 | + $courses_result = array(); |
|
301 | + $category_names = array(); |
|
302 | + |
|
303 | + $courses = CourseManager::get_courses_list(); |
|
304 | + foreach($courses as $course) { |
|
305 | + $course_tmp = array(); |
|
306 | + $course_tmp['id'] = $course['id']; |
|
307 | + $course_tmp['code'] = $course['code']; |
|
308 | + $course_tmp['title'] = $course['title']; |
|
309 | + $course_tmp['language'] = $course['course_language']; |
|
310 | + $course_tmp['visibility'] = $course['visibility']; |
|
311 | + |
|
312 | + // Determining category name |
|
313 | + if($category_names[$course['category_code']]) { |
|
314 | + $course_tmp['category_name'] = $category_names[$course['category_code']]; |
|
315 | + } else { |
|
316 | + $category = CourseManager::get_course_category($course['category_code']); |
|
317 | + $category_names[$course['category_code']] = $category['name']; |
|
318 | + $course_tmp['category_name'] = $category['name']; |
|
319 | + } |
|
320 | + |
|
321 | + // Determining number of students registered in course |
|
322 | + $user_list = CourseManager::get_user_list_from_course_code($course['code']); |
|
323 | + $course_tmp['number_students'] = count($user_list); |
|
324 | + |
|
325 | + // Determining external course id |
|
326 | + $course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_id_field_name, $course['code']); |
|
327 | + |
|
328 | + |
|
329 | + $courses_result[] = $course_tmp; |
|
330 | + } |
|
331 | + |
|
332 | + return $courses_result; |
|
333 | + } |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * Subscribe or unsubscribe user to a course (helper method) |
|
338 | + * |
|
339 | + * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
340 | + * @param string Course id value. |
|
341 | + * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
342 | + * @param string User id value |
|
343 | + * @param int Set to 1 to subscribe, 0 to unsubscribe |
|
344 | + * @param int Status (STUDENT or TEACHER) Used for subscription only |
|
345 | + * @return mixed True if subscription or unsubscription was successful, false otherwise |
|
346 | + */ |
|
347 | + protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) { |
|
348 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
349 | + if($course_id instanceof WSError) { |
|
350 | + return $course_id; |
|
351 | + } else { |
|
352 | + $user_id = $this->getUserId($user_id_field_name, $user_id_value); |
|
353 | + if($user_id instanceof WSError) { |
|
354 | + return $user_id; |
|
355 | + } else { |
|
356 | + $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
357 | + if($state == 0) { |
|
358 | + // Unsubscribe user |
|
359 | + CourseManager::unsubscribe_user($user_id, $course_code); |
|
360 | + return true; |
|
361 | + } else { |
|
362 | + // Subscribe user |
|
363 | + if(CourseManager::subscribe_user($user_id, $course_code, $status)) { |
|
364 | + return true; |
|
365 | + } else { |
|
366 | + return new WSError(203, 'An error occured subscribing to this course'); |
|
367 | + } |
|
368 | + } |
|
369 | + } |
|
370 | + } |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * Subscribe user to a course |
|
375 | + * |
|
376 | + * @param string API secret key |
|
377 | + * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
378 | + * @param string Course id value. |
|
379 | + * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
380 | + * @param string User id value |
|
381 | + * @param int Status (1 = Teacher, 5 = Student) |
|
382 | + */ |
|
383 | + public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) { |
|
384 | + $verifKey = $this->verifyKey($secret_key); |
|
385 | + if($verifKey instanceof WSError) { |
|
386 | + $this->handleError($verifKey); |
|
387 | + } else { |
|
388 | + $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status); |
|
389 | + if($result instanceof WSError) { |
|
390 | + $this->handleError($result); |
|
391 | + } |
|
392 | + } |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Unsusbscribe user from course |
|
397 | + * |
|
398 | + * @param string API secret key |
|
399 | + * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
400 | + * @param string Course id value. |
|
401 | + * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
402 | + * @param string User id value |
|
403 | + */ |
|
404 | + public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) { |
|
405 | + $verifKey = $this->verifyKey($secret_key); |
|
406 | + if($verifKey instanceof WSError) { |
|
407 | + $this->handleError($verifKey); |
|
408 | + } else { |
|
409 | + $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0); |
|
410 | + if($result instanceof WSError) { |
|
411 | + $this->handleError($result); |
|
412 | + } |
|
413 | + } |
|
414 | + } |
|
415 | + |
|
416 | + /** |
|
417 | + * Returns the descriptions of a course, along with their id |
|
418 | + * |
|
419 | + * @param string API secret key |
|
420 | + * @param string Course id field name |
|
421 | + * @param string Course id value |
|
422 | + * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content') |
|
423 | + */ |
|
424 | + public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) { |
|
425 | + $verifKey = $this->verifyKey($secret_key); |
|
426 | + if($verifKey instanceof WSError) { |
|
427 | + $this->handleError($verifKey); |
|
428 | + } else { |
|
429 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
430 | + if($course_id instanceof WSError) { |
|
431 | + return $course_id; |
|
432 | + } else { |
|
433 | + // Course exists, get its descriptions |
|
434 | + $descriptions = CourseDescription::get_descriptions($course_id); |
|
435 | + $results = array(); |
|
436 | + foreach($descriptions as $description) { |
|
437 | + $results[] = array('course_desc_id' => $description->get_description_type(), |
|
438 | + 'course_desc_title' => $description->get_title(), |
|
439 | + 'course_desc_content' => $description->get_content()); |
|
440 | + } |
|
441 | + return $results; |
|
442 | + } |
|
443 | + } |
|
444 | + } |
|
445 | + |
|
446 | + |
|
447 | + /** |
|
448 | + * Edit course description |
|
449 | + * |
|
450 | + * @param string API secret key |
|
451 | + * @param string Course id field name |
|
452 | + * @param string Course id value |
|
453 | + * @param int Category id from course description |
|
454 | + * @param string Description title |
|
455 | + * @param string Course description content |
|
456 | + */ |
|
457 | + public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) { |
|
458 | + $verifKey = $this->verifyKey($secret_key); |
|
459 | + if($verifKey instanceof WSError) { |
|
460 | + $this->handleError($verifKey); |
|
461 | + } else { |
|
462 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
463 | + if($course_id instanceof WSError) { |
|
464 | + return $course_id; |
|
465 | + } else { |
|
466 | + // Create the new course description |
|
467 | + $cd = new CourseDescription(); |
|
468 | + $cd->set_description_type($course_desc_id); |
|
469 | + $cd->set_title($course_desc_title); |
|
470 | + $cd->set_content($course_desc_content); |
|
471 | + $cd->set_session_id(0); |
|
472 | + |
|
473 | + // Get course info |
|
474 | 474 | $course_info = CourseManager::get_course_information( |
475 | 475 | CourseManager::get_course_code_from_course_id($course_id) |
476 | 476 | ); |
477 | - // Check if this course description exists |
|
478 | - $descriptions = CourseDescription::get_descriptions($course_id); |
|
479 | - $exists = false; |
|
480 | - foreach($descriptions as $description) { |
|
481 | - if($description->get_description_type() == $course_desc_id) { |
|
482 | - $exists = true; |
|
483 | - } |
|
484 | - } |
|
477 | + // Check if this course description exists |
|
478 | + $descriptions = CourseDescription::get_descriptions($course_id); |
|
479 | + $exists = false; |
|
480 | + foreach($descriptions as $description) { |
|
481 | + if($description->get_description_type() == $course_desc_id) { |
|
482 | + $exists = true; |
|
483 | + } |
|
484 | + } |
|
485 | 485 | $cd->set_course_id($course_info['real_id']); |
486 | - if (!$exists) { |
|
487 | - $cd->set_progress(0); |
|
488 | - $cd->insert(); |
|
489 | - } else { |
|
490 | - $cd->update(); |
|
491 | - } |
|
492 | - } |
|
493 | - } |
|
494 | - } |
|
495 | - public function unreadMessage($username, $password) |
|
496 | - { |
|
497 | - if($this->verifyUserPass($username, $password) == "valid") |
|
498 | - { |
|
499 | - $table_message = Database::get_main_table(TABLE_MESSAGE); |
|
500 | - $user_id = UserManager::get_user_id_from_username($username); |
|
501 | - $condition_msg_status = ' msg_status = 1 '; // define('MESSAGE_STATUS_UNREAD', '1'); |
|
502 | - |
|
503 | - $sql_query = "SELECT COUNT(*) as number_messages FROM $table_message WHERE $condition_msg_status AND user_receiver_id=".$user_id; |
|
504 | - |
|
505 | - $sql_result = Database::query($sql_query); |
|
506 | - $result = Database::fetch_array($sql_result); |
|
507 | - return $result['number_messages']; |
|
508 | - } |
|
509 | - return "0"; |
|
510 | - } |
|
511 | - |
|
512 | - public function get_message_data($username, $password) |
|
513 | - { |
|
514 | - if($this->verifyUserPass($username, $password) == "valid") |
|
515 | - { |
|
516 | - $user_id = get_user_id_from_username($username); |
|
517 | - |
|
518 | - } |
|
519 | - |
|
520 | - } |
|
521 | - |
|
522 | - public function nada($username, $password) |
|
523 | - { |
|
524 | - if($this->verifyUserPass($username, $password) == "valid") |
|
525 | - return $username.$password; |
|
526 | - return $username; |
|
527 | - } |
|
486 | + if (!$exists) { |
|
487 | + $cd->set_progress(0); |
|
488 | + $cd->insert(); |
|
489 | + } else { |
|
490 | + $cd->update(); |
|
491 | + } |
|
492 | + } |
|
493 | + } |
|
494 | + } |
|
495 | + public function unreadMessage($username, $password) |
|
496 | + { |
|
497 | + if($this->verifyUserPass($username, $password) == "valid") |
|
498 | + { |
|
499 | + $table_message = Database::get_main_table(TABLE_MESSAGE); |
|
500 | + $user_id = UserManager::get_user_id_from_username($username); |
|
501 | + $condition_msg_status = ' msg_status = 1 '; // define('MESSAGE_STATUS_UNREAD', '1'); |
|
502 | + |
|
503 | + $sql_query = "SELECT COUNT(*) as number_messages FROM $table_message WHERE $condition_msg_status AND user_receiver_id=".$user_id; |
|
504 | + |
|
505 | + $sql_result = Database::query($sql_query); |
|
506 | + $result = Database::fetch_array($sql_result); |
|
507 | + return $result['number_messages']; |
|
508 | + } |
|
509 | + return "0"; |
|
510 | + } |
|
511 | + |
|
512 | + public function get_message_data($username, $password) |
|
513 | + { |
|
514 | + if($this->verifyUserPass($username, $password) == "valid") |
|
515 | + { |
|
516 | + $user_id = get_user_id_from_username($username); |
|
517 | + |
|
518 | + } |
|
519 | + |
|
520 | + } |
|
521 | + |
|
522 | + public function nada($username, $password) |
|
523 | + { |
|
524 | + if($this->verifyUserPass($username, $password) == "valid") |
|
525 | + return $username.$password; |
|
526 | + return $username; |
|
527 | + } |
|
528 | 528 | |
529 | 529 | |
530 | 530 |
@@ -12,490 +12,490 @@ |
||
12 | 12 | */ |
13 | 13 | class WSCourse extends WS |
14 | 14 | { |
15 | - /** |
|
16 | - * Deletes a course (helper method) |
|
17 | - * |
|
18 | - * @param string Course id field name |
|
19 | - * @param string Course id value |
|
20 | - * @return mixed True if the course was successfully deleted, WSError otherwise |
|
21 | - */ |
|
22 | - protected function deleteCourseHelper($course_id_field_name, $course_id_value) { |
|
23 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
24 | - if($course_id instanceof WSError) { |
|
25 | - return $course_id; |
|
26 | - } else { |
|
27 | - $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
28 | - CourseManager::delete_course($course_code); |
|
29 | - return true; |
|
30 | - } |
|
31 | - } |
|
15 | + /** |
|
16 | + * Deletes a course (helper method) |
|
17 | + * |
|
18 | + * @param string Course id field name |
|
19 | + * @param string Course id value |
|
20 | + * @return mixed True if the course was successfully deleted, WSError otherwise |
|
21 | + */ |
|
22 | + protected function deleteCourseHelper($course_id_field_name, $course_id_value) { |
|
23 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
24 | + if($course_id instanceof WSError) { |
|
25 | + return $course_id; |
|
26 | + } else { |
|
27 | + $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
28 | + CourseManager::delete_course($course_code); |
|
29 | + return true; |
|
30 | + } |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Deletes a course |
|
35 | - * |
|
36 | - * @param string API secret key |
|
37 | - * @param string Course id field name |
|
38 | - * @param string Course id value |
|
39 | - */ |
|
40 | - public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) { |
|
41 | - $verifKey = $this->verifyKey($secret_key); |
|
42 | - if($verifKey instanceof WSError) { |
|
43 | - $this->handleError($verifKey); |
|
44 | - } else { |
|
45 | - $result = $this->deleteCourseHelper($course_id_field_name, $course_id_value); |
|
46 | - if($result instanceof WSError) { |
|
47 | - $this->handleError($result); |
|
48 | - } |
|
49 | - } |
|
50 | - } |
|
33 | + /** |
|
34 | + * Deletes a course |
|
35 | + * |
|
36 | + * @param string API secret key |
|
37 | + * @param string Course id field name |
|
38 | + * @param string Course id value |
|
39 | + */ |
|
40 | + public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) { |
|
41 | + $verifKey = $this->verifyKey($secret_key); |
|
42 | + if($verifKey instanceof WSError) { |
|
43 | + $this->handleError($verifKey); |
|
44 | + } else { |
|
45 | + $result = $this->deleteCourseHelper($course_id_field_name, $course_id_value); |
|
46 | + if($result instanceof WSError) { |
|
47 | + $this->handleError($result); |
|
48 | + } |
|
49 | + } |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Deletes multiple courses |
|
54 | - * |
|
55 | - * @param string API secret key |
|
56 | - * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value') |
|
57 | - * @return array Array with elements like array('course_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). Note that if the result array contains a code different |
|
58 | - * than 0, an error occured |
|
59 | - */ |
|
60 | - public function DeleteCourses($secret_key, $courses) { |
|
61 | - $verifKey = $this->verifyKey($secret_key); |
|
62 | - if($verifKey instanceof WSError) { |
|
63 | - $this->handleError($verifKey); |
|
64 | - } else { |
|
65 | - $results = array(); |
|
66 | - foreach($courses as $course) { |
|
67 | - $result_tmp = array(); |
|
68 | - $result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']); |
|
69 | - $result_tmp['course_id_value'] = $course['course_id_value']; |
|
70 | - if($result_op instanceof WSError) { |
|
71 | - // Return the error in the results |
|
72 | - $result_tmp['result'] = $result_op->toArray(); |
|
73 | - } else { |
|
74 | - $result_tmp['result'] = $this->getSuccessfulResult(); |
|
75 | - } |
|
76 | - $results[] = $result_tmp; |
|
77 | - } |
|
78 | - return $results; |
|
79 | - } |
|
80 | - } |
|
52 | + /** |
|
53 | + * Deletes multiple courses |
|
54 | + * |
|
55 | + * @param string API secret key |
|
56 | + * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value') |
|
57 | + * @return array Array with elements like array('course_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). Note that if the result array contains a code different |
|
58 | + * than 0, an error occured |
|
59 | + */ |
|
60 | + public function DeleteCourses($secret_key, $courses) { |
|
61 | + $verifKey = $this->verifyKey($secret_key); |
|
62 | + if($verifKey instanceof WSError) { |
|
63 | + $this->handleError($verifKey); |
|
64 | + } else { |
|
65 | + $results = array(); |
|
66 | + foreach($courses as $course) { |
|
67 | + $result_tmp = array(); |
|
68 | + $result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']); |
|
69 | + $result_tmp['course_id_value'] = $course['course_id_value']; |
|
70 | + if($result_op instanceof WSError) { |
|
71 | + // Return the error in the results |
|
72 | + $result_tmp['result'] = $result_op->toArray(); |
|
73 | + } else { |
|
74 | + $result_tmp['result'] = $this->getSuccessfulResult(); |
|
75 | + } |
|
76 | + $results[] = $result_tmp; |
|
77 | + } |
|
78 | + return $results; |
|
79 | + } |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Creates a course (helper method) |
|
84 | - * |
|
85 | - * @param string Title |
|
86 | - * @param string Category code |
|
87 | - * @param string Wanted code. If it's not defined, it will be generated automatically |
|
88 | - * @param string Tutor name |
|
89 | - * @param string Course admin user id field name |
|
90 | - * @param string Course admin user id value |
|
91 | - * @param string Course language |
|
92 | - * @param string Course id field name |
|
93 | - * @param string Course id value |
|
94 | - * @param array Course extra fields |
|
95 | - * @return mixed Generated id if creation was successful, WSError otherwise |
|
96 | - */ |
|
97 | - protected function createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) { |
|
98 | - // Add the original course id field name and value to the extra fields if needed |
|
99 | - $extras_associative = array(); |
|
100 | - if($course_id_field_name != "chamilo_course_id") { |
|
101 | - $extras_associative[$course_id_field_name] = $course_id_value; |
|
102 | - } |
|
103 | - foreach($extras as $extra) { |
|
104 | - $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
105 | - } |
|
106 | - $course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value); |
|
107 | - if($course_admin_id instanceof WSError) { |
|
108 | - return $course_admin_id; |
|
109 | - } |
|
110 | - if($wanted_code == '') { |
|
111 | - $wanted_code = CourseManager::generate_course_code($title); |
|
112 | - } |
|
113 | - $result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0); |
|
114 | - if (!$result) { |
|
115 | - return new WSError(202, 'There was an error creating the course'); |
|
116 | - } else { |
|
117 | - // Update extra fields |
|
118 | - foreach($extras_associative as $fname => $fvalue) { |
|
119 | - CourseManager::update_course_extra_field_value($result, $fname, $fvalue); |
|
120 | - } |
|
121 | - // Get course id |
|
122 | - $course_info = CourseManager::get_course_information($result); |
|
123 | - return $course_info['real_id']; |
|
124 | - } |
|
125 | - } |
|
82 | + /** |
|
83 | + * Creates a course (helper method) |
|
84 | + * |
|
85 | + * @param string Title |
|
86 | + * @param string Category code |
|
87 | + * @param string Wanted code. If it's not defined, it will be generated automatically |
|
88 | + * @param string Tutor name |
|
89 | + * @param string Course admin user id field name |
|
90 | + * @param string Course admin user id value |
|
91 | + * @param string Course language |
|
92 | + * @param string Course id field name |
|
93 | + * @param string Course id value |
|
94 | + * @param array Course extra fields |
|
95 | + * @return mixed Generated id if creation was successful, WSError otherwise |
|
96 | + */ |
|
97 | + protected function createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) { |
|
98 | + // Add the original course id field name and value to the extra fields if needed |
|
99 | + $extras_associative = array(); |
|
100 | + if($course_id_field_name != "chamilo_course_id") { |
|
101 | + $extras_associative[$course_id_field_name] = $course_id_value; |
|
102 | + } |
|
103 | + foreach($extras as $extra) { |
|
104 | + $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
105 | + } |
|
106 | + $course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value); |
|
107 | + if($course_admin_id instanceof WSError) { |
|
108 | + return $course_admin_id; |
|
109 | + } |
|
110 | + if($wanted_code == '') { |
|
111 | + $wanted_code = CourseManager::generate_course_code($title); |
|
112 | + } |
|
113 | + $result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0); |
|
114 | + if (!$result) { |
|
115 | + return new WSError(202, 'There was an error creating the course'); |
|
116 | + } else { |
|
117 | + // Update extra fields |
|
118 | + foreach($extras_associative as $fname => $fvalue) { |
|
119 | + CourseManager::update_course_extra_field_value($result, $fname, $fvalue); |
|
120 | + } |
|
121 | + // Get course id |
|
122 | + $course_info = CourseManager::get_course_information($result); |
|
123 | + return $course_info['real_id']; |
|
124 | + } |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * Creates a course |
|
129 | - * |
|
130 | - * @param string API secret key |
|
131 | - * @param string Title |
|
132 | - * @param string Category code |
|
133 | - * @param string Wanted code. If it's not defined, it will be generated automatically |
|
134 | - * @param string Tutor name |
|
135 | - * @param string Course admin user id field name |
|
136 | - * @param string Course admin user id value |
|
137 | - * @param string Course language |
|
138 | - * @param string Course id field name |
|
139 | - * @param string Course id value |
|
140 | - * @param array Course extra fields |
|
141 | - * @return int Course id generated |
|
142 | - */ |
|
143 | - public function CreateCourse($secret_key, $title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) { |
|
144 | - // First, verify the secret key |
|
145 | - $verifKey = $this->verifyKey($secret_key); |
|
146 | - if($verifKey instanceof WSError) { |
|
147 | - $this->handleError($verifKey); |
|
148 | - } else { |
|
149 | - $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras); |
|
150 | - if($result instanceof WSError) { |
|
151 | - $this->handleError($result); |
|
152 | - } else { |
|
153 | - return $result; |
|
154 | - } |
|
155 | - } |
|
156 | - } |
|
127 | + /** |
|
128 | + * Creates a course |
|
129 | + * |
|
130 | + * @param string API secret key |
|
131 | + * @param string Title |
|
132 | + * @param string Category code |
|
133 | + * @param string Wanted code. If it's not defined, it will be generated automatically |
|
134 | + * @param string Tutor name |
|
135 | + * @param string Course admin user id field name |
|
136 | + * @param string Course admin user id value |
|
137 | + * @param string Course language |
|
138 | + * @param string Course id field name |
|
139 | + * @param string Course id value |
|
140 | + * @param array Course extra fields |
|
141 | + * @return int Course id generated |
|
142 | + */ |
|
143 | + public function CreateCourse($secret_key, $title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) { |
|
144 | + // First, verify the secret key |
|
145 | + $verifKey = $this->verifyKey($secret_key); |
|
146 | + if($verifKey instanceof WSError) { |
|
147 | + $this->handleError($verifKey); |
|
148 | + } else { |
|
149 | + $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras); |
|
150 | + if($result instanceof WSError) { |
|
151 | + $this->handleError($result); |
|
152 | + } else { |
|
153 | + return $result; |
|
154 | + } |
|
155 | + } |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * Create multiple courses |
|
160 | - * |
|
161 | - * @param string API secret key |
|
162 | - * @param array Courses to be created, with elements following the structure presented in CreateCourse |
|
163 | - * @return array Array with elements of the form array('course_id_value' => 'original value sent', 'course_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful')) |
|
164 | - */ |
|
165 | - public function CreateCourses($secret_key, $courses) { |
|
166 | - // First, verify the secret key |
|
167 | - $verifKey = $this->verifyKey($secret_key); |
|
168 | - if($verifKey instanceof WSError) { |
|
169 | - $this->handleError($verifKey); |
|
170 | - } else { |
|
171 | - $results = array(); |
|
172 | - foreach($courses as $course) { |
|
173 | - $result_tmp = array(); |
|
158 | + /** |
|
159 | + * Create multiple courses |
|
160 | + * |
|
161 | + * @param string API secret key |
|
162 | + * @param array Courses to be created, with elements following the structure presented in CreateCourse |
|
163 | + * @return array Array with elements of the form array('course_id_value' => 'original value sent', 'course_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful')) |
|
164 | + */ |
|
165 | + public function CreateCourses($secret_key, $courses) { |
|
166 | + // First, verify the secret key |
|
167 | + $verifKey = $this->verifyKey($secret_key); |
|
168 | + if($verifKey instanceof WSError) { |
|
169 | + $this->handleError($verifKey); |
|
170 | + } else { |
|
171 | + $results = array(); |
|
172 | + foreach($courses as $course) { |
|
173 | + $result_tmp = array(); |
|
174 | 174 | // re-initialize variables just in case |
175 | 175 | $title = $category_code = $wanted_code = $tutor_name = $course_admin_user_id_field_name = $course_admin_user_id_value = $language = $course_id_field_name = $course_id_value = $extras = 0; |
176 | - extract($course); |
|
177 | - $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras); |
|
178 | - if($result instanceof WSError) { |
|
179 | - $result_tmp['result'] = $result->toArray(); |
|
180 | - $result_tmp['course_id_value'] = $course_id_value; |
|
181 | - $result_tmp['course_id_generated'] = 0; |
|
182 | - } else { |
|
183 | - $result_tmp['result'] = $this->getSuccessfulResult(); |
|
184 | - $result_tmp['course_id_value'] = $course_id_value; |
|
185 | - $result_tmp['course_id_generated'] = $result; |
|
186 | - } |
|
187 | - $results[] = $result_tmp; |
|
188 | - } |
|
189 | - return $results; |
|
190 | - } |
|
191 | - } |
|
176 | + extract($course); |
|
177 | + $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras); |
|
178 | + if($result instanceof WSError) { |
|
179 | + $result_tmp['result'] = $result->toArray(); |
|
180 | + $result_tmp['course_id_value'] = $course_id_value; |
|
181 | + $result_tmp['course_id_generated'] = 0; |
|
182 | + } else { |
|
183 | + $result_tmp['result'] = $this->getSuccessfulResult(); |
|
184 | + $result_tmp['course_id_value'] = $course_id_value; |
|
185 | + $result_tmp['course_id_generated'] = $result; |
|
186 | + } |
|
187 | + $results[] = $result_tmp; |
|
188 | + } |
|
189 | + return $results; |
|
190 | + } |
|
191 | + } |
|
192 | 192 | |
193 | - /** |
|
194 | - * Edits a course (helper method) |
|
195 | - * |
|
196 | - * @param string Course id field name |
|
197 | - * @param string Course id value |
|
198 | - * @param string Title |
|
199 | - * @param string Category code |
|
200 | - * @param string Department name |
|
201 | - * @param string Department url |
|
202 | - * @param string Course language |
|
203 | - * @param int Visibility |
|
204 | - * @param int Subscribe (0 = denied, 1 = allowed) |
|
205 | - * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
206 | - * @param string Visual code |
|
207 | - * @param array Course extra fields |
|
208 | - * @return mixed True in case of success, WSError otherwise |
|
209 | - */ |
|
210 | - protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
|
211 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
212 | - if($course_id instanceof WSError) { |
|
213 | - return $course_id; |
|
214 | - } else { |
|
215 | - $attributes = array(); |
|
216 | - if(!empty($title)) { |
|
217 | - $attributes['title'] = $title; |
|
218 | - } |
|
219 | - if(!empty($category_code)) { |
|
220 | - $attributes['category_code'] = $category_code; |
|
221 | - } |
|
222 | - if(!empty($department_name)) { |
|
223 | - $attributes['department_name'] = $department_name; |
|
224 | - } |
|
225 | - if(!empty($department_url)) { |
|
226 | - $attributes['department_url'] = $department_url; |
|
227 | - } |
|
228 | - if(!empty($language)) { |
|
229 | - $attributes['course_language'] = $language; |
|
230 | - } |
|
231 | - if($visibility != '') { |
|
232 | - $attributes['visibility'] = (int)$visibility; |
|
233 | - } |
|
234 | - if($subscribe != '') { |
|
235 | - $attributes['subscribe'] = (int)$subscribe; |
|
236 | - } |
|
237 | - if($unsubscribe != '') { |
|
238 | - $attributes['unsubscribe'] = (int)$unsubscribe; |
|
239 | - } |
|
240 | - if(!empty($visual_code)) { |
|
241 | - $attributes['visual_code'] = $visual_code; |
|
242 | - } |
|
243 | - if(!empty($attributes)) { |
|
244 | - CourseManager::update_attributes($course_id, $attributes); |
|
245 | - } |
|
246 | - if(!empty($extras)) { |
|
247 | - $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
248 | - $extras_associative = array(); |
|
249 | - foreach($extras as $extra) { |
|
250 | - $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
251 | - } |
|
252 | - foreach($extras_associative as $fname => $fvalue) { |
|
253 | - CourseManager::update_extra_field_value($course_code, $fname, $fvalue); |
|
254 | - } |
|
255 | - } |
|
256 | - return true; |
|
257 | - } |
|
258 | - } |
|
193 | + /** |
|
194 | + * Edits a course (helper method) |
|
195 | + * |
|
196 | + * @param string Course id field name |
|
197 | + * @param string Course id value |
|
198 | + * @param string Title |
|
199 | + * @param string Category code |
|
200 | + * @param string Department name |
|
201 | + * @param string Department url |
|
202 | + * @param string Course language |
|
203 | + * @param int Visibility |
|
204 | + * @param int Subscribe (0 = denied, 1 = allowed) |
|
205 | + * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
206 | + * @param string Visual code |
|
207 | + * @param array Course extra fields |
|
208 | + * @return mixed True in case of success, WSError otherwise |
|
209 | + */ |
|
210 | + protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
|
211 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
212 | + if($course_id instanceof WSError) { |
|
213 | + return $course_id; |
|
214 | + } else { |
|
215 | + $attributes = array(); |
|
216 | + if(!empty($title)) { |
|
217 | + $attributes['title'] = $title; |
|
218 | + } |
|
219 | + if(!empty($category_code)) { |
|
220 | + $attributes['category_code'] = $category_code; |
|
221 | + } |
|
222 | + if(!empty($department_name)) { |
|
223 | + $attributes['department_name'] = $department_name; |
|
224 | + } |
|
225 | + if(!empty($department_url)) { |
|
226 | + $attributes['department_url'] = $department_url; |
|
227 | + } |
|
228 | + if(!empty($language)) { |
|
229 | + $attributes['course_language'] = $language; |
|
230 | + } |
|
231 | + if($visibility != '') { |
|
232 | + $attributes['visibility'] = (int)$visibility; |
|
233 | + } |
|
234 | + if($subscribe != '') { |
|
235 | + $attributes['subscribe'] = (int)$subscribe; |
|
236 | + } |
|
237 | + if($unsubscribe != '') { |
|
238 | + $attributes['unsubscribe'] = (int)$unsubscribe; |
|
239 | + } |
|
240 | + if(!empty($visual_code)) { |
|
241 | + $attributes['visual_code'] = $visual_code; |
|
242 | + } |
|
243 | + if(!empty($attributes)) { |
|
244 | + CourseManager::update_attributes($course_id, $attributes); |
|
245 | + } |
|
246 | + if(!empty($extras)) { |
|
247 | + $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
248 | + $extras_associative = array(); |
|
249 | + foreach($extras as $extra) { |
|
250 | + $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
251 | + } |
|
252 | + foreach($extras_associative as $fname => $fvalue) { |
|
253 | + CourseManager::update_extra_field_value($course_code, $fname, $fvalue); |
|
254 | + } |
|
255 | + } |
|
256 | + return true; |
|
257 | + } |
|
258 | + } |
|
259 | 259 | |
260 | - /** |
|
261 | - * Edits a course |
|
262 | - * |
|
263 | - * @param string API secret key |
|
264 | - * @param string Course id field name |
|
265 | - * @param string Course id value |
|
266 | - * @param string Title |
|
267 | - * @param string Category code |
|
268 | - * @param string Department name |
|
269 | - * @param string Department url |
|
270 | - * @param string Course language |
|
271 | - * @param int Visibility |
|
272 | - * @param int Subscribe (0 = denied, 1 = allowed) |
|
273 | - * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
274 | - * @param string Visual code |
|
275 | - * @param array Course extra fields |
|
276 | - */ |
|
277 | - public function EditCourse($secret_key, $course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
|
278 | - $verifKey = $this->verifyKey($secret_key); |
|
279 | - if($verifKey instanceof WSError) { |
|
280 | - $this->handleError($verifKey); |
|
281 | - } else { |
|
282 | - $result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras); |
|
283 | - if($result instanceof WSError) { |
|
284 | - $this->handleError($result); |
|
285 | - } |
|
286 | - } |
|
287 | - } |
|
260 | + /** |
|
261 | + * Edits a course |
|
262 | + * |
|
263 | + * @param string API secret key |
|
264 | + * @param string Course id field name |
|
265 | + * @param string Course id value |
|
266 | + * @param string Title |
|
267 | + * @param string Category code |
|
268 | + * @param string Department name |
|
269 | + * @param string Department url |
|
270 | + * @param string Course language |
|
271 | + * @param int Visibility |
|
272 | + * @param int Subscribe (0 = denied, 1 = allowed) |
|
273 | + * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
274 | + * @param string Visual code |
|
275 | + * @param array Course extra fields |
|
276 | + */ |
|
277 | + public function EditCourse($secret_key, $course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
|
278 | + $verifKey = $this->verifyKey($secret_key); |
|
279 | + if($verifKey instanceof WSError) { |
|
280 | + $this->handleError($verifKey); |
|
281 | + } else { |
|
282 | + $result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras); |
|
283 | + if($result instanceof WSError) { |
|
284 | + $this->handleError($result); |
|
285 | + } |
|
286 | + } |
|
287 | + } |
|
288 | 288 | |
289 | - /** |
|
290 | - * List courses |
|
291 | - * |
|
292 | - * @param string API secret key |
|
293 | - * @param string A list of visibility filter we want to apply |
|
294 | - * @return array An array with elements of the form ('id' => 'Course internal id', 'code' => 'Course code', 'title' => 'Course title', 'language' => 'Course language', 'visibility' => 'Course visibility', |
|
295 | - * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id') |
|
296 | - */ |
|
297 | - public function ListCourses($secret_key, $visibility = 'public,public-registered,private,closed') { |
|
298 | - $verifKey = $this->verifyKey($secret_key); |
|
299 | - if($verifKey instanceof WSError) { |
|
300 | - $this->handleError($verifKey); |
|
301 | - } else { |
|
289 | + /** |
|
290 | + * List courses |
|
291 | + * |
|
292 | + * @param string API secret key |
|
293 | + * @param string A list of visibility filter we want to apply |
|
294 | + * @return array An array with elements of the form ('id' => 'Course internal id', 'code' => 'Course code', 'title' => 'Course title', 'language' => 'Course language', 'visibility' => 'Course visibility', |
|
295 | + * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id') |
|
296 | + */ |
|
297 | + public function ListCourses($secret_key, $visibility = 'public,public-registered,private,closed') { |
|
298 | + $verifKey = $this->verifyKey($secret_key); |
|
299 | + if($verifKey instanceof WSError) { |
|
300 | + $this->handleError($verifKey); |
|
301 | + } else { |
|
302 | 302 | $visibilities = split(',',$visibility); |
303 | 303 | $vis = array('public' => '3', 'public-registered' => '2', 'private' => '1', 'closed' => '0'); |
304 | 304 | foreach ($visibilities as $p => $visibility) { |
305 | 305 | $visibilities[$p] = $vis[$visibility]; |
306 | 306 | } |
307 | - $courses_result = array(); |
|
308 | - $category_names = array(); |
|
307 | + $courses_result = array(); |
|
308 | + $category_names = array(); |
|
309 | 309 | |
310 | - $courses = CourseManager::get_courses_list(); |
|
311 | - foreach($courses as $course) { |
|
310 | + $courses = CourseManager::get_courses_list(); |
|
311 | + foreach($courses as $course) { |
|
312 | 312 | //skip elements that do not match required visibility |
313 | 313 | if (!in_array($course['visibility'],$visibilities)) { continue; } |
314 | - $course_tmp = array(); |
|
315 | - $course_tmp['id'] = $course['id']; |
|
316 | - $course_tmp['code'] = $course['code']; |
|
317 | - $course_tmp['title'] = $course['title']; |
|
318 | - $course_tmp['language'] = $course['course_language']; |
|
319 | - $course_tmp['visibility'] = $course['visibility']; |
|
314 | + $course_tmp = array(); |
|
315 | + $course_tmp['id'] = $course['id']; |
|
316 | + $course_tmp['code'] = $course['code']; |
|
317 | + $course_tmp['title'] = $course['title']; |
|
318 | + $course_tmp['language'] = $course['course_language']; |
|
319 | + $course_tmp['visibility'] = $course['visibility']; |
|
320 | 320 | |
321 | - // Determining category name |
|
322 | - if($category_names[$course['category_code']]) { |
|
323 | - $course_tmp['category_name'] = $category_names[$course['category_code']]; |
|
324 | - } else { |
|
325 | - $category = CourseManager::get_course_category($course['category_code']); |
|
326 | - $category_names[$course['category_code']] = $category['name']; |
|
327 | - $course_tmp['category_name'] = $category['name']; |
|
328 | - } |
|
321 | + // Determining category name |
|
322 | + if($category_names[$course['category_code']]) { |
|
323 | + $course_tmp['category_name'] = $category_names[$course['category_code']]; |
|
324 | + } else { |
|
325 | + $category = CourseManager::get_course_category($course['category_code']); |
|
326 | + $category_names[$course['category_code']] = $category['name']; |
|
327 | + $course_tmp['category_name'] = $category['name']; |
|
328 | + } |
|
329 | 329 | |
330 | - // Determining number of students registered in course |
|
331 | - $user_list = CourseManager::get_user_list_from_course_code($course['code'], 0); |
|
332 | - $course_tmp['number_students'] = count($user_list); |
|
330 | + // Determining number of students registered in course |
|
331 | + $user_list = CourseManager::get_user_list_from_course_code($course['code'], 0); |
|
332 | + $course_tmp['number_students'] = count($user_list); |
|
333 | 333 | |
334 | - // Determining external course id - this code misses the external course id field name |
|
335 | - // $course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_field_name, $course['code']); |
|
334 | + // Determining external course id - this code misses the external course id field name |
|
335 | + // $course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_field_name, $course['code']); |
|
336 | 336 | |
337 | 337 | |
338 | - $courses_result[] = $course_tmp; |
|
339 | - } |
|
338 | + $courses_result[] = $course_tmp; |
|
339 | + } |
|
340 | 340 | |
341 | - return $courses_result; |
|
342 | - } |
|
343 | - } |
|
341 | + return $courses_result; |
|
342 | + } |
|
343 | + } |
|
344 | 344 | |
345 | - /** |
|
346 | - * Subscribe or unsubscribe user to a course (helper method) |
|
347 | - * |
|
348 | - * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
349 | - * @param string Course id value. |
|
350 | - * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
351 | - * @param string User id value |
|
352 | - * @param int Set to 1 to subscribe, 0 to unsubscribe |
|
353 | - * @param int Status (STUDENT or TEACHER) Used for subscription only |
|
354 | - * @return mixed True if subscription or unsubscription was successful, false otherwise |
|
355 | - */ |
|
356 | - protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) { |
|
357 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
358 | - if($course_id instanceof WSError) { |
|
359 | - return $course_id; |
|
360 | - } else { |
|
361 | - $user_id = $this->getUserId($user_id_field_name, $user_id_value); |
|
362 | - if($user_id instanceof WSError) { |
|
363 | - return $user_id; |
|
364 | - } else { |
|
365 | - $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
366 | - if($state == 0) { |
|
367 | - // Unsubscribe user |
|
368 | - CourseManager::unsubscribe_user($user_id, $course_code); |
|
369 | - return true; |
|
370 | - } else { |
|
371 | - // Subscribe user |
|
372 | - if(CourseManager::subscribe_user($user_id, $course_code, $status)) { |
|
373 | - return true; |
|
374 | - } else { |
|
375 | - return new WSError(203, 'An error occured subscribing to this course'); |
|
376 | - } |
|
377 | - } |
|
378 | - } |
|
379 | - } |
|
380 | - } |
|
345 | + /** |
|
346 | + * Subscribe or unsubscribe user to a course (helper method) |
|
347 | + * |
|
348 | + * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
349 | + * @param string Course id value. |
|
350 | + * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
351 | + * @param string User id value |
|
352 | + * @param int Set to 1 to subscribe, 0 to unsubscribe |
|
353 | + * @param int Status (STUDENT or TEACHER) Used for subscription only |
|
354 | + * @return mixed True if subscription or unsubscription was successful, false otherwise |
|
355 | + */ |
|
356 | + protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) { |
|
357 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
358 | + if($course_id instanceof WSError) { |
|
359 | + return $course_id; |
|
360 | + } else { |
|
361 | + $user_id = $this->getUserId($user_id_field_name, $user_id_value); |
|
362 | + if($user_id instanceof WSError) { |
|
363 | + return $user_id; |
|
364 | + } else { |
|
365 | + $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
366 | + if($state == 0) { |
|
367 | + // Unsubscribe user |
|
368 | + CourseManager::unsubscribe_user($user_id, $course_code); |
|
369 | + return true; |
|
370 | + } else { |
|
371 | + // Subscribe user |
|
372 | + if(CourseManager::subscribe_user($user_id, $course_code, $status)) { |
|
373 | + return true; |
|
374 | + } else { |
|
375 | + return new WSError(203, 'An error occured subscribing to this course'); |
|
376 | + } |
|
377 | + } |
|
378 | + } |
|
379 | + } |
|
380 | + } |
|
381 | 381 | |
382 | - /** |
|
383 | - * Subscribe user to a course |
|
384 | - * |
|
385 | - * @param string API secret key |
|
386 | - * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
387 | - * @param string Course id value. |
|
388 | - * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
389 | - * @param string User id value |
|
390 | - * @param int Status (1 = Teacher, 5 = Student) |
|
391 | - */ |
|
392 | - public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) { |
|
393 | - $verifKey = $this->verifyKey($secret_key); |
|
394 | - if($verifKey instanceof WSError) { |
|
395 | - $this->handleError($verifKey); |
|
396 | - } else { |
|
397 | - $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status); |
|
398 | - if($result instanceof WSError) { |
|
399 | - $this->handleError($result); |
|
400 | - } |
|
401 | - } |
|
402 | - } |
|
382 | + /** |
|
383 | + * Subscribe user to a course |
|
384 | + * |
|
385 | + * @param string API secret key |
|
386 | + * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
387 | + * @param string Course id value. |
|
388 | + * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
389 | + * @param string User id value |
|
390 | + * @param int Status (1 = Teacher, 5 = Student) |
|
391 | + */ |
|
392 | + public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) { |
|
393 | + $verifKey = $this->verifyKey($secret_key); |
|
394 | + if($verifKey instanceof WSError) { |
|
395 | + $this->handleError($verifKey); |
|
396 | + } else { |
|
397 | + $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status); |
|
398 | + if($result instanceof WSError) { |
|
399 | + $this->handleError($result); |
|
400 | + } |
|
401 | + } |
|
402 | + } |
|
403 | 403 | |
404 | - /** |
|
405 | - * Unsusbscribe user from course |
|
406 | - * |
|
407 | - * @param string API secret key |
|
408 | - * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
409 | - * @param string Course id value. |
|
410 | - * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
411 | - * @param string User id value |
|
412 | - */ |
|
413 | - public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) { |
|
414 | - $verifKey = $this->verifyKey($secret_key); |
|
415 | - if($verifKey instanceof WSError) { |
|
416 | - $this->handleError($verifKey); |
|
417 | - } else { |
|
418 | - $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0); |
|
419 | - if($result instanceof WSError) { |
|
420 | - $this->handleError($result); |
|
421 | - } |
|
422 | - } |
|
423 | - } |
|
404 | + /** |
|
405 | + * Unsusbscribe user from course |
|
406 | + * |
|
407 | + * @param string API secret key |
|
408 | + * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
409 | + * @param string Course id value. |
|
410 | + * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
411 | + * @param string User id value |
|
412 | + */ |
|
413 | + public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) { |
|
414 | + $verifKey = $this->verifyKey($secret_key); |
|
415 | + if($verifKey instanceof WSError) { |
|
416 | + $this->handleError($verifKey); |
|
417 | + } else { |
|
418 | + $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0); |
|
419 | + if($result instanceof WSError) { |
|
420 | + $this->handleError($result); |
|
421 | + } |
|
422 | + } |
|
423 | + } |
|
424 | 424 | |
425 | - /** |
|
426 | - * Returns the descriptions of a course, along with their id |
|
427 | - * |
|
428 | - * @param string API secret key |
|
429 | - * @param string Course id field name |
|
430 | - * @param string Course id value |
|
431 | - * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content') |
|
432 | - */ |
|
433 | - public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) { |
|
434 | - $verifKey = $this->verifyKey($secret_key); |
|
435 | - if($verifKey instanceof WSError) { |
|
436 | - $this->handleError($verifKey); |
|
437 | - } else { |
|
438 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
439 | - if($course_id instanceof WSError) { |
|
440 | - return $course_id; |
|
441 | - } else { |
|
442 | - // Course exists, get its descriptions |
|
443 | - $descriptions = CourseDescription::get_descriptions($course_id); |
|
444 | - $results = array(); |
|
445 | - foreach($descriptions as $description) { |
|
446 | - $results[] = array('course_desc_id' => $description->get_description_type(), |
|
447 | - 'course_desc_title' => $description->get_title(), |
|
448 | - 'course_desc_content' => $description->get_content()); |
|
449 | - } |
|
450 | - return $results; |
|
451 | - } |
|
452 | - } |
|
453 | - } |
|
425 | + /** |
|
426 | + * Returns the descriptions of a course, along with their id |
|
427 | + * |
|
428 | + * @param string API secret key |
|
429 | + * @param string Course id field name |
|
430 | + * @param string Course id value |
|
431 | + * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content') |
|
432 | + */ |
|
433 | + public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) { |
|
434 | + $verifKey = $this->verifyKey($secret_key); |
|
435 | + if($verifKey instanceof WSError) { |
|
436 | + $this->handleError($verifKey); |
|
437 | + } else { |
|
438 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
439 | + if($course_id instanceof WSError) { |
|
440 | + return $course_id; |
|
441 | + } else { |
|
442 | + // Course exists, get its descriptions |
|
443 | + $descriptions = CourseDescription::get_descriptions($course_id); |
|
444 | + $results = array(); |
|
445 | + foreach($descriptions as $description) { |
|
446 | + $results[] = array('course_desc_id' => $description->get_description_type(), |
|
447 | + 'course_desc_title' => $description->get_title(), |
|
448 | + 'course_desc_content' => $description->get_content()); |
|
449 | + } |
|
450 | + return $results; |
|
451 | + } |
|
452 | + } |
|
453 | + } |
|
454 | 454 | |
455 | 455 | |
456 | - /** |
|
457 | - * Edit course description |
|
458 | - * |
|
459 | - * @param string API secret key |
|
460 | - * @param string Course id field name |
|
461 | - * @param string Course id value |
|
462 | - * @param int Category id from course description |
|
463 | - * @param string Description title |
|
464 | - * @param string Course description content |
|
465 | - */ |
|
466 | - public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) { |
|
467 | - $verifKey = $this->verifyKey($secret_key); |
|
468 | - if($verifKey instanceof WSError) { |
|
469 | - $this->handleError($verifKey); |
|
470 | - } else { |
|
471 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
472 | - if($course_id instanceof WSError) { |
|
473 | - return $course_id; |
|
474 | - } else { |
|
475 | - // Create the new course description |
|
476 | - $cd = new CourseDescription(); |
|
477 | - $cd->set_description_type($course_desc_id); |
|
478 | - $cd->set_title($course_desc_title); |
|
479 | - $cd->set_content($course_desc_content); |
|
480 | - $cd->set_session_id(0); |
|
481 | - // Get course info |
|
482 | - $course_info = CourseManager::get_course_information(CourseManager::get_course_code_from_course_id($course_id)); |
|
456 | + /** |
|
457 | + * Edit course description |
|
458 | + * |
|
459 | + * @param string API secret key |
|
460 | + * @param string Course id field name |
|
461 | + * @param string Course id value |
|
462 | + * @param int Category id from course description |
|
463 | + * @param string Description title |
|
464 | + * @param string Course description content |
|
465 | + */ |
|
466 | + public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) { |
|
467 | + $verifKey = $this->verifyKey($secret_key); |
|
468 | + if($verifKey instanceof WSError) { |
|
469 | + $this->handleError($verifKey); |
|
470 | + } else { |
|
471 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
472 | + if($course_id instanceof WSError) { |
|
473 | + return $course_id; |
|
474 | + } else { |
|
475 | + // Create the new course description |
|
476 | + $cd = new CourseDescription(); |
|
477 | + $cd->set_description_type($course_desc_id); |
|
478 | + $cd->set_title($course_desc_title); |
|
479 | + $cd->set_content($course_desc_content); |
|
480 | + $cd->set_session_id(0); |
|
481 | + // Get course info |
|
482 | + $course_info = CourseManager::get_course_information(CourseManager::get_course_code_from_course_id($course_id)); |
|
483 | 483 | $cd->set_course_id($course_info['real_id']); |
484 | - // Check if this course description exists |
|
485 | - $descriptions = CourseDescription::get_descriptions($course_id); |
|
486 | - $exists = false; |
|
487 | - foreach($descriptions as $description) { |
|
488 | - if($description->get_description_type() == $course_desc_id) { |
|
489 | - $exists = true; |
|
490 | - } |
|
491 | - } |
|
492 | - if (!$exists) { |
|
493 | - $cd->set_progress(0); |
|
494 | - $cd->insert(); |
|
495 | - } else { |
|
496 | - $cd->update(); |
|
497 | - } |
|
498 | - } |
|
499 | - } |
|
500 | - } |
|
484 | + // Check if this course description exists |
|
485 | + $descriptions = CourseDescription::get_descriptions($course_id); |
|
486 | + $exists = false; |
|
487 | + foreach($descriptions as $description) { |
|
488 | + if($description->get_description_type() == $course_desc_id) { |
|
489 | + $exists = true; |
|
490 | + } |
|
491 | + } |
|
492 | + if (!$exists) { |
|
493 | + $cd->set_progress(0); |
|
494 | + $cd->insert(); |
|
495 | + } else { |
|
496 | + $cd->update(); |
|
497 | + } |
|
498 | + } |
|
499 | + } |
|
500 | + } |
|
501 | 501 | } |
@@ -6,24 +6,24 @@ |
||
6 | 6 | */ |
7 | 7 | class HTML_QuickForm_Compare_Fields extends HTML_QuickForm_Rule_Compare |
8 | 8 | { |
9 | - /** |
|
10 | - * Function to check an array of fields |
|
11 | - * @param array of field names |
|
9 | + /** |
|
10 | + * Function to check an array of fields |
|
11 | + * @param array of field names |
|
12 | 12 | * @param string operator ==, >=, etc |
13 | 13 | * @param string the value to compare |
14 | - * @return boolean True if date is valid |
|
15 | - */ |
|
16 | - function validate($values = [], $operator_and_max_value = null) { |
|
14 | + * @return boolean True if date is valid |
|
15 | + */ |
|
16 | + function validate($values = [], $operator_and_max_value = null) { |
|
17 | 17 | if (is_array($values) && !empty($values) && !empty($operator_and_max_value)) { |
18 | - $final_value = 0; |
|
19 | - foreach ($values as $value) { |
|
20 | - $final_value += $value; |
|
21 | - } |
|
22 | - $params = explode('@', $operator_and_max_value); |
|
23 | - $operator = $params[0]; |
|
24 | - $max_value = $params[1]; |
|
25 | - return parent::validate(array($final_value, $max_value), $operator); |
|
18 | + $final_value = 0; |
|
19 | + foreach ($values as $value) { |
|
20 | + $final_value += $value; |
|
21 | + } |
|
22 | + $params = explode('@', $operator_and_max_value); |
|
23 | + $operator = $params[0]; |
|
24 | + $max_value = $params[1]; |
|
25 | + return parent::validate(array($final_value, $max_value), $operator); |
|
26 | 26 | } |
27 | 27 | return false; |
28 | - } |
|
28 | + } |
|
29 | 29 | } |
30 | 30 | \ No newline at end of file |