Skip to content
Snippets Groups Projects
locallib.php 54.2 KiB
Newer Older
  • Learn to ignore specific revisions
  • DFNVC's avatar
    DFNVC committed
    <?php
    
    /**
     * @package mod
     * @subpackage adobeconnect
     * @author Akinsaya Delamarre (adelamarre@remote-learner.net)
     * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
     */
    
    require_once('connect_class.php');
    require_once('connect_class_dom.php');
    
    define('ADOBE_VIEW_ROLE', 'view');
    define('ADOBE_HOST_ROLE', 'host');
    define('ADOBE_MINIADMIN_ROLE', 'mini-host');
    define('ADOBE_REMOVE_ROLE', 'remove');
    
    define('ADOBE_PARTICIPANT', 1);
    define('ADOBE_PRESENTER', 2);
    define('ADOBE_REMOVE', 3);
    define('ADOBE_HOST', 4);
    
    define('ADOBE_TEMPLATE_POSTFIX', '- Template');
    define('ADOBE_MEETING_POSTFIX', '- Meeting');
    
    define('ADOBE_MEETPERM_PUBLIC', 0); //means the Acrobat Connect meeting is public, and anyone who has the URL for the meeting can enter the room.
    define('ADOBE_MEETPERM_PROTECTED', 1); //means the meeting is protected, and only registered users and accepted guests can enter the room.
    define('ADOBE_MEETPERM_PRIVATE', 2); // means the meeting is private, and only registered users and participants can enter the room
    
    define('ADOBE_TMZ_LENGTH', 6);
    
    /* DFNVC 
    function adobe_connection_test($host = '', $port = 80, $username = '',
                                   $password = '', $httpheader = '',
                                   $emaillogin, $https = false) {
    */
    
    function adobe_connection_test($host = '', $port = 80, $username = '',
                                   $password = '',
                                   $emaillogin, $https = false) {
        global $CFG;
        if (empty($host) or
            empty($port) or (0 == $port) or
            empty($username) or
            empty($password))
    	/* DFNVC
    	  or empty($httpheader)) { */
    	{
    
            echo "</p>One of the required parameters is blank or incorrect: <br />".
                 "Host: $host<br /> Port: $port<br /> Username: $username<br /> Password: $password".
                 "<br /> HTTP Header: $httpheader</p>";
    
            die();
        }
    
        $messages = array();
    
        $aconnectDOM = new connect_class_dom($host,
                                             $port,
                                             $username,
                                             $password,
                                             '',
                                             $https);
    
        $params = array(
            'action' => 'common-info'
        );
    
        // Send common-info call to obtain the session key
        echo '<p><b>Sending common-info call:</b></p>';
        $aconnectDOM->create_request($params);
    
        if (!empty($aconnectDOM->_xmlresponse)) {
    
            // Get the session key from the XML response
            $aconnectDOM->read_cookie_xml($aconnectDOM->_xmlresponse);
    
            $cookie = $aconnectDOM->get_cookie();
            if (empty($cookie)) {
    
                echo '<p>unable to obtain session key from common-info call</p>';
                echo '<p>xmlrequest:</p>';
                $doc = new DOMDocument();
    
                if ($doc->loadXML($aconnectDOM->_xmlrequest)) {
                    echo '<p>' . htmlspecialchars($doc->saveXML()) . '</p>';
                } else {
                    echo '<p>unable to display the XML request</p>';
    
                }
    
                echo '<p>xmlresponse:</p>';
                $doc = new DOMDocument();
    
                if ($doc->loadXML($aconnectDOM->_xmlresponse)) {
                    echo '<p>' . htmlspecialchars($doc->saveHTML()) . '</p>';
                } else {
                    echo '<p>unable to display the XML response</p>';
                }
            } else {
    
                // print success
                echo '<p style="color:#006633">successfully obtained the session key: ' . $aconnectDOM->get_cookie() . '</p>';
    	    $sessionkey =  $aconnectDOM->get_cookie();
    
                // Test logging in as the administrator
                echo '<p><b>Test logging in as administrator.</b></p>';
                $params = array(
                      'action' => 'login',
                      'login' => $aconnectDOM->get_username(),
                      'password' => $aconnectDOM->get_password() . '',
                );
                $aconnectDOM->create_request($params);
    
    
                if ($aconnectDOM->call_success()) {
    		echo '<p style="color:#006633">successfully logged in as '. $username . '</p>';
    		// DFNVC
    		// Test header login
    		//
    		/* echo '<p><b>Testing header login:</b><p>'; */
    		/* if ($aconnectDOM->request_http_header_login(1, $username)) { */
    		/*     echo '<p style="color:#006633">successfully logged in as user ' . $username . '</p>'; */
    		/*     echo '<p>cookie:' . $aconnectDOM->get_cookie() .'<p>'; */
    
    		/* } */
    		/* else { */
    		/*     echo '<p>header login for user ' . $username . ' failed<p>'; */
    		/* } */
    
                    // Test retrevial of folders
                    echo '<p><b>Testing retrevial of content folder:</b></p>';
                    $folderscoid = aconnect_get_content_folder($aconnectDOM);
    
                    if ($folderscoid) {
                        echo '<p style="color:#006633">successfully obtained content folder scoid '. $folderscoid . '</p>';
                    } else {
    
                        echo '<p>error obtaining shared content folder</p>';
                        echo '<p style="color:#680000">XML request:<br />'. htmlspecialchars($aconnectDOM->_xmlrequest). '</p>';
                        echo '<p style="color:#680000">XML response:<br />'. htmlspecialchars($aconnectDOM->_xmlresponse). '</p>';
    
                    }
    
    		// DFNVC
    		// Testing retrieval of meeting folder sco-id
    		//
                    echo '<p><b>Testing retrevial of meetings folder:</b></p>';		
    		$meetingfolderscoid = aconnect_get_meeting_folder($aconnectDOM);
                    if ($meetingfolderscoid) {
                        echo '<p style="color:#006633">successfully obtained meeting folder scoid '. $meetingfolderscoid . '</p>';
                    } else {
                        echo '<p>error obtaining meeting folder sco-id</p>';
                        echo '<p style="color:#680000">XML request:<br />'. htmlspecialchars($aconnectDOM->_xmlrequest). '</p>';
                        echo '<p style="color:#680000">XML response:<br />'. htmlspecialchars($aconnectDOM->_xmlresponse). '</p>';
                    }
    		// DFNVC
    		// Testing retrieval of shared template folder
    		// TODO
                    echo '<p><b>Testing retrevial of shared meeting templates:</b></p>';		
    		$templates = aconnect_get_templates_meetings($aconnectDOM);
                    if ($templates) {
                        echo '<p style="color:#006633">successfully obtained shared templates :</p>';
                        echo '<p style="color:#006633">';
    		    foreach (array_keys($templates) as $key) {
    			echo $templates[$key] . '<br>';
    		    }
    		    echo '</p>';
                    } else {
                        echo '<p>error obtaining shared templates.</p>';
                        echo '<p style="color:#680000">XML request:<br />'. htmlspecialchars($aconnectDOM->_xmlrequest). '</p>';
                        echo '<p style="color:#680000">XML response:<br />'. htmlspecialchars($aconnectDOM->_xmlresponse). '</p>';
                    }
    		
    
    DFNVC's avatar
    DFNVC committed
                    // Test creating a meeting
    
    DFNVC's avatar
    DFNVC committed
                    echo '<p><b>Test creating a meeting:</b></p>';
    
                    $res = preg_split('/@/',$username);
                    $testdomain = $res[1];
    
    DFNVC's avatar
    DFNVC committed
    
                    $meeting = new stdClass();
                    $meeting->name = "MoodleTestMeeting for $testdomain";
                    $time = time();
                    $meeting->starttime = $time;
                    $time = $time + (60 * 60);
                    $meeting->endtime = $time;
    
                    if (($meetingscoid = aconnect_create_meeting($aconnectDOM, $meeting, $meetingfolderscoid))) {
                        echo '<p style="color:#006633">successfully created meeting <b>\'' . $meeting->name . '\'</b> with scoid '. $meetingscoid . '</p>';
                    } else {
                        echo '<p>error creating meeting <b>' . $meeting->name . '</b> folder</p>';
                        echo '<p style="color:#680000">XML request:<br />'. htmlspecialchars($aconnectDOM->_xmlrequest). '</p>';
                        echo '<p style="color:#680000">XML response:<br />'. htmlspecialchars($aconnectDOM->_xmlresponse). '</p>';
                    }
    
    		// DFNVC
    		// Test making meeting public
    		//
    		echo '<p><b>Test making meeting public:</b></p>';
    		if (aconnect_update_meeting_perm($aconnectDOM, $meetingscoid, 'ADOBE_MEETPERM_PUBLIC')) {
                        echo '<p style="color:#006633">successfully made meeting <b>\'' . $meeting->name . '\'</b> public</p>';
    		}
    		else {
                        echo '<p>error makeing meeting public:</p>';
                        echo '<p style="color:#680000">XML request:<br />'. htmlspecialchars($aconnectDOM->_xmlrequest). '</p>';
                        echo '<p style="color:#680000">XML response:<br />'. htmlspecialchars($aconnectDOM->_xmlresponse). '</p>';		    
    		}
    
    
    DFNVC's avatar
    DFNVC committed
    		// DFNVC
    		//
                    echo '<p><b>Test creating a user:</b></p>';		
                    $user = new stdClass();
    
                    $res = preg_split('/@/',$username);
                    $apiuserdomain = $res[1];
                    
    
    DFNVC's avatar
    DFNVC committed
                    $user->email = 'MoodleTestUser@' . $apiuserdomain;
    
                    $user->username = $user->email;
    
    DFNVC's avatar
    DFNVC committed
    221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
                    $user->firstname = 'Moodle Test User';
                    $user->lastname = 'GROUP';
    
                    if (!($usrprincipal = lms_user_exists($aconnectDOM, $user))) {
                          $usrprincipal = aconnect_create_user($aconnectDOM, $user);
    		    if ($usrprincipal) {
                            echo '<p style="color:#006633">successfully created user <b>' . $user->username . '</b> with principal-id '. $usrprincipal . '</p>';
                        } else {
                            echo '<p style="color:#680000">error creating testuser user <b>' . $user->username . '</b></p>';
                            echo '<p style="color:#680000">XML request:<br />'. htmlspecialchars($aconnectDOM->_xmlrequest). '</p>';
                            echo '<p style="color:#680000">XML response:<br />'. htmlspecialchars($aconnectDOM->_xmlresponse). '</p>';
                            aconnect_logout($aconnectDOM);
                            die();
                        }
                    } else {
                        echo '<p style="color:#006633">user ' . $user->username . ' already exists, skipping ... </p>';
                    }
    
    		// Test roles
    		//
                    echo '<p><b>Test creating and removing meeting role for user ' . $user->username . ' :</b></p>';		
                    // Assign test user a meeting role
                    if (aconnect_check_user_perm($aconnectDOM, $usrprincipal, $meetingscoid, ADOBE_PRESENTER, true)) {
                        echo '<p style="color:#006633">successfully assigned ' .
    			' presenter role to user in meeting <b>\'' . $meeting->name . '\'</b>.</p>';
                    } else {
                            echo '<p style="color:#680000">error assigning user presenter role in meeting <b>' . $meeting->name . '</b></p>';
                            echo '<p style="color:#680000">XML request:<br />'. htmlspecialchars($aconnectDOM->_xmlrequest). '</p>';
                            echo '<p style="color:#680000">XML response:<br />'. htmlspecialchars($aconnectDOM->_xmlresponse). '</p>';
                    }
    
                    // Remove meeting role from user
    		//
                    if (aconnect_check_user_perm($aconnectDOM, $usrprincipal, $meetingscoid, ADOBE_REMOVE_ROLE, true)) {
                        echo '<p style="color:#006633">successfully removed presenter role from user '.
                             ' in meeting <b>\'' . $meeting->name . '\'</b>.</p>';
                    } else {
                            echo '<p style="color:#680000">error removing presenter role for user <b>' . $user->username . '</b> in meeting <b>\'' . $meeting->name . '\'</b></p>';
                            echo '<p style="color:#680000">XML request:<br />'. htmlspecialchars($aconnectDOM->_xmlrequest). '</p>';
                            echo '<p style="color:#680000">XML response:<br />'. htmlspecialchars($aconnectDOM->_xmlresponse). '</p>';
                    }
    
    		// Get session key for test user
    		//
                    echo '<p><b>Test getting a session key for user ' . $user->username . ':</b></p>';		
    
    		if ($session_cookie = $aconnectDOM->user_session_cookie($user->username)) {
    		    echo '<p style="color:#006633">Successfully got session cookie <b>'. $session_cookie . '</b> for user';
    		}
    		else {
    		    echo '<p style="color:#680000">Getting session key for user ' . $user->username . ' failed<p>';
    		    echo '<p style="color:#680000">XML request:<br />'. htmlspecialchars($aconnectDOM->_xmlrequest). '</p>';
    		    echo '<p style="color:#680000">XML response:<br />'. htmlspecialchars($aconnectDOM->_xmlresponse). '</p>';
    		}
    		
                    // Test removing user from server
    		//
                    echo '<p><b>Test removing user from server:</b></p>';		
                    if ($usrprincipal) {
                        if (aconnect_delete_user($aconnectDOM, $usrprincipal)) {
                            echo '<p style="color:#006633">successfully removed user with principal-id '. $usrprincipal . '</p>';
                        } else {
                            echo '<p>error removing user <b>' . $user->username . '</b></p>';
                            echo '<p style="color:#680000">XML request:<br />'. htmlspecialchars($aconnectDOM->_xmlrequest). '</p>';
                            echo '<p style="color:#680000">XML response:<br />'. htmlspecialchars($aconnectDOM->_xmlresponse). '</p>';
                        }
                    }
    
                    // Test removing meeting from server
    		//
                    echo '<p><b>Test removing a meeting from server:</b></p>';		
                    if ($meetingscoid) {
                        if (aconnect_remove_meeting($aconnectDOM, $meetingscoid)) {
                            echo '<p style="color:#006633">successfully removed meeting <b>' . $meeting->name . '</b> ('. $meetingscoid . ')</p>';
                        } else {
                            echo '<p>error removing meeting <b>' . $meeting->name . '</b> folder</p>';
                            echo '<p style="color:#680000">XML request:<br />'. htmlspecialchars($aconnectDOM->_xmlrequest). '</p>';
                            echo '<p style="color:#680000">XML response:<br />'. htmlspecialchars($aconnectDOM->_xmlresponse). '</p>';
                        }
                    }
    
    		// Test removing dummy meeting from server
    		//
                    echo '<p><b>Test removing dummy meeting from server:</b></p>';		
    		if (aconnect_remove_meeting($aconnectDOM, '134737')) {
    		    echo '<p style="color:#680000">error: successfully removed dummy meeting</p>';
    		} else {
    		    echo '<p style="color:#006633">success: could not remove dummy meeting</p>';
    		}
    
                    // Test removing dummy recording from server
    		//
                    echo '<p><b>Test removing dummy recording from server:</b></p>';		
    		if (aconnect_remove_meeting($aconnectDOM, '134763')) {
    		    echo '<p style="color:#680000">error: successfully removed dummy recording</p>';
    		} else {
    		    echo '<p style="color:#006633">success: could not remove dummy recording</p>';
    		}
    
                } else {
                    echo '<p style="color:#680000">logging in as '. $username . ' was not successful, check to see if the username and password are correct </p>';
                }
           }
    
        } else {
            echo '<p style="color:#680000">common-info API call returned an empty document.  Please check your settings and try again </p>';
        }
        echo '<p><hr><p>';
        aconnect_logout($aconnectDOM);
    
    }
    
    /**
     * Returns the folder sco-id
     * @param object an adobe connection_class object
     * @param string $folder name of the folder to get
     * (ex. forced-archives = recording folder | meetings = meetings folder
     * | content = shared content folder)
     * @return mixed adobe connect folder sco-id || false if there was an error
     *
     */
    function aconnect_get_folder($aconnect, $folder = '') {
        $folderscoid = false;
        $params = array('action' => 'sco-shortcuts');
    
        $aconnect->create_request($params);
    
        if ($aconnect->call_success()) {
            $folderscoid = aconnect_get_folder_sco_id($aconnect->_xmlresponse, $folder);
    //        $params = array('action' => 'sco-contents', 'sco-id' => $folderscoid);
        }
    
        return $folderscoid;
    }
    
    /**
     * TODO: comment function and return something meaningful
     */
    function aconnect_get_folder_sco_id($xml, $folder) {
        $scoid = false;
    
        $dom = new DomDocument();
        $dom->loadXML($xml);
    
        $domnodelist = $dom->getElementsByTagName('sco');
    
        if (!empty($domnodelist->length)) {
    
            for ($i = 0; $i < $domnodelist->length; $i++) {
    
                $domnode = $domnodelist->item($i)->attributes->getNamedItem('type');
    
                if (!is_null($domnode)) {
    
                    if (0 == strcmp($folder, $domnode->nodeValue)) {
                        $domnode = $domnodelist->item($i)->attributes->getNamedItem('sco-id');
    
                        if (!is_null($domnode)) {
                            $scoid = (int) $domnode->nodeValue;
    
                        }
                    }
                }
            }
        }
    
        return $scoid;
    
    }
    
    //
    // DFNVC
    // Get user's meetings folder sco-id
    //
    function aconnect_get_user_folder($aconnect, $meetingsscoid, $folder = '') {
        $folderscoid = false;
        $params = array('action' => 'sco-contents',
                        'sco-id' => $meetingsscoid,
                        'filter-name' => $folder,
                        );
        $aconnect->create_request($params);
    
        if ($aconnect->call_success()) {
          $xmldoc = new DomDocument();
          $xmldoc->loadXML($aconnect->_xmlresponse);
          $xpath = new DomXpath($xmldoc);
          $folderscoid = $xpath->query("//sco/@sco-id")->item(0)->nodeValue;
        }
        return $folderscoid;
    }
    
    //
    // DFNVC
    // 
    function aconnect_get_meeting_folder($aconnect) {
      global $DB;
      $ac = new stdClass();
      $param = array('name' => 'adobeconnect_admin_login');
      $username = $DB->get_field('config', 'value', $param);
      $folderscoid = aconnect_get_folder($aconnect, 'user-meetings');
      $folderscoid = aconnect_get_user_folder($aconnect, $folderscoid, $username); 
      return $folderscoid;
    }
    
    //
    // DFNVC
    // 
    function aconnect_get_content_folder($aconnect) {
      global $DB;
      $ac = new stdClass();
      $param = array('name' => 'adobeconnect_admin_login');
      $username = $DB->get_field('config', 'value', $param);
      $folderscoid = aconnect_get_folder($aconnect, 'user-content');
      $folderscoid = aconnect_get_user_folder($aconnect, $folderscoid, $username); 
      return $folderscoid;
    }
    
    /**
     * Log in as the admin user.  This should only be used to conduct API calls.
     */
    function aconnect_login() {
        global $CFG, $USER, $COURSE;
    
        if (!isset($CFG->adobeconnect_host) or
            !isset($CFG->adobeconnect_admin_login) or
            !isset($CFG->adobeconnect_admin_password)) {
                if (is_siteadmin($USER->id)) {
                    notice(get_string('adminnotsetupproperty', 'adobeconnect'),
                           $CFG->wwwroot . '/admin/settings.php?section=modsettingadobeconnect');
                } else {
                    notice(get_string('notsetupproperty', 'adobeconnect'),
                           '', $COURSE);
                }
        }
    
        if (isset($CFG->adobeconnect_port) and
            !empty($CFG->adobeconnect_port) and
            ((80 != $CFG->adobeconnect_port) and (0 != $CFG->adobeconnect_port))) {
            $port = $CFG->adobeconnect_port;
        } else {
            $port = 80;
        }
    
        $https = false;
    
        if (isset($CFG->adobeconnect_https) and (!empty($CFG->adobeconnect_https))) {
            $https = true;
        }
    
    
        $aconnect = new connect_class_dom($CFG->adobeconnect_host,
                                          $CFG->adobeconnect_port,
                                          $CFG->adobeconnect_admin_login,
                                          $CFG->adobeconnect_admin_password,
                                          '',
                                          $https);
    
        $params = array(
            'action' => 'common-info'
        );
    
        $aconnect->create_request($params);
    
        $aconnect->read_cookie_xml($aconnect->_xmlresponse);
    
        $params = array(
              'action' => 'login',
              'login' => $aconnect->get_username(),
              'password' => $aconnect->get_password(),
        );
    
        $aconnect->create_request($params);
    
        if ($aconnect->call_success()) {
            $aconnect->set_connection(1);
        } else {
            $aconnect->set_connection(0);
        }
    
        return $aconnect;
    }
    
    
    /**
     * Logout
     * @param object $aconnect - connection object
     * @return true on success else false
     */
    function aconnect_logout(&$aconnect) {
        if (!$aconnect->get_connection()) {
            return true;
        }
    
        $params = array('action' => 'logout');
        $aconnect->create_request($params);
    
        if ($aconnect->call_success()) {
            $aconnect->set_connection(0);
            return true;
        } else {
            $aconnect->set_connection(1);
            return false;
        }
    }
    
    /**
     * Calls all operations needed to retrieve and return all
     * templates defined in the shared templates folder and meetings
     * @param object $aconnect connection object
     * @return array $templates an array of templates
     */
    function aconnect_get_templates_meetings($aconnect) {
        $templates = array();
        $meetings = array();
        $meetfldscoid = false;
        $tempfldscoid = false;
    
        $params = array(
            'action' => 'sco-shortcuts',
        );
    
        $aconnect->create_request($params);
    
        if ($aconnect->call_success()) {
            // Get shared templates folder sco-id
            $tempfldscoid = aconnect_get_shared_templates($aconnect->_xmlresponse);
        }
    
        if (false !== $tempfldscoid) {
            $params = array(
                'action' => 'sco-expanded-contents',
                'sco-id' => $tempfldscoid,
            );
    
            $aconnect->create_request($params);
    
            if ($aconnect->call_success()) {
                $templates = aconnect_return_all_templates($aconnect->_xmlresponse);
            }
        }
    
    //    if (false !== $meetfldscoid) {
    //        $params = array(
    //            'action' => 'sco-expanded-contents',
    //            'sco-id' => $meetfldscoid,
    //            'filter-type' => 'meeting',
    //        );
    //
    //        $aconnect->create_request($params);
    //
    //        if ($aconnect->call_success()) {
    //            $meetings = aconnect_return_all_meetings($aconnect->_xmlresponse);
    //        }
    //
    //    }
    
        return $templates + $meetings;
    }
    
    /**
     * Parse XML looking for shared-meeting-templates attribute
     * and returning the sco-id of the folder
     * @param string $xml returned XML from a sco-shortcuts call
     * @return mixed sco-id if found or false if not found or error
     */
    function aconnect_get_shared_templates($xml) {
        $scoid = false;
    
        $dom = new DomDocument();
        $dom->loadXML($xml);
    
        $domnodelist = $dom->getElementsByTagName('shortcuts');
    
        if (!empty($domnodelist->length)) {
    
    //        for ($i = 0; $i < $domnodelist->length; $i++) {
    
                $innerlist = $domnodelist->item(0)->getElementsByTagName('sco');
    
                if (!empty($innerlist->length)) {
    
                    for ($x = 0; $x < $innerlist->length; $x++) {
    
                        if ($innerlist->item($x)->hasAttributes()) {
    
                            $domnode = $innerlist->item($x)->attributes->getNamedItem('type');
    
                            if (!is_null($domnode)) {
    
                                if (0 == strcmp('shared-meeting-templates', $domnode->nodeValue)) {
                                    $domnode = $innerlist->item($x)->attributes->getNamedItem('sco-id');
    
                                    if (!is_null($domnode)) {
                                        $scoid = (int) $domnode->nodeValue;
                                    }
                                }
                            }
                        }
                    }
                }
    //        }
    
        }
    
        return $scoid;
    }
    
    function aconnect_return_all_meetings($xml) {
        $meetings = array();
        $xml = new SimpleXMLElement($xml);
    
        if (empty($xml)) {
            return $meetings;
        }
    
        foreach($xml->{'expanded-scos'}[0]->sco as $key => $sco) {
            if (0 == strcmp('meeting', $sco['type'])) {
                $mkey = (int) $sco['sco-id'];
                $meetings[$mkey] = (string) current($sco->name) .' '. ADOBE_MEETING_POSTFIX;
            }
        }
    
        return $meetings;
    }
    
    /**
     * Parses XML for meeting templates and returns an array
     * with sco-id as the key and template name as the value
     * @param strimg $xml XML returned from a sco-expanded-contents call
     * @return array of templates sco-id -> key, name -> value
     */
    function aconnect_return_all_templates($xml) {
        $templates = array();
    
        $dom = new DomDocument();
        $dom->loadXML($xml);
    
        $domnodelist = $dom->getElementsByTagName('expanded-scos');
    
        if (!empty($domnodelist->length)) {
    
            $innerlist = $domnodelist->item(0)->getElementsByTagName('sco');
    
            if (!empty($innerlist->length)) {
    
                for ($i = 0; $i < $innerlist->length; $i++) {
    
                    if ($innerlist->item($i)->hasAttributes()) {
                        $domnode = $innerlist->item($i)->attributes->getNamedItem('type');
    
                        if (!is_null($domnode) and 0 == strcmp('meeting', $domnode->nodeValue)) {
                            $domnode = $innerlist->item($i)->attributes->getNamedItem('sco-id');
    
                            if (!is_null($domnode)) {
                                $tkey = (int) $domnode->nodeValue;
                                $namelistnode = $innerlist->item($i)->getElementsByTagName('name');
    
                                if (!is_null($namelistnode)) {
                                    $name = $namelistnode->item(0)->nodeValue;
                                    $templates[$tkey] = (string) $name .' ' . ADOBE_TEMPLATE_POSTFIX;
                                }
                            }
                        }
                    }
                }
            }
        }
    
        return $templates;
    }
    
    // DFNVC
    // Get Recording url-path
    //
    function aconnect_get_recording_urlpath($aconnect, $meetingscoid, $recordingscoid) {
      $params = array('action' => 'sco-contents',
    		  'sco-id' => $meetingscoid,
    		  'filter-sco-id' => $recordingscoid
    		  );
      $aconnect->create_request($params);
    
      if ($aconnect->call_success()) {
          $xmldoc = new DomDocument();
          $xmldoc->loadXML($aconnect->_xmlresponse);
          $xpath = new DomXpath($xmldoc);
          $url = $xpath->query("//sco/url-path")->item(0)->nodeValue;
          return $url;
      }
      else {
          return '';
      }
    }
    
    /**
     * Returns information about all recordings that belong to a specific
     * meeting sco-id
     *
     * @param obj $aconnect a connect_class object
     * @param int $folderscoid the recordings folder sco-id
     * @param int $sourcescoid the meeting sco-id
     *
     * @return mixed array an array of object with the recording sco-id
     * as the key and the recording properties as properties
     */
    function aconnect_get_recordings($aconnect, $folderscoid, $sourcescoid) {
        $params = array('action' => 'sco-contents',
                        'sco-id' => $folderscoid,
                        //'filter-source-sco-id' => $sourcescoid,
    		    //
    		    // DFNVC Quickfix - 29.08.2013
    		    // Nur Aufnahemen anzeigen
    		    'filter-icon' => 'archive',
    		    //
                        'sort-name' => 'asc',
                        );
    
        // Check if meeting scoid and folder scoid are the same
        // If hey are the same then that means that forced recordings is not
        // enabled filter-source-sco-id should not be included.  If they the
        // meeting scoid and folder scoid are not equal then forced recordings
        // are enabled and we can use filter by filter-source-sco-id
        // Thanks to A. gtdino
        if ($sourcescoid != $folderscoid) {
            $params['filter-source-sco-id'] = $sourcescoid;
        }
    
        $aconnect->create_request($params);
    
        $recordings = array();
    
        if ($aconnect->call_success()) {
            $dom = new DomDocument();
            $dom->loadXML($aconnect->_xmlresponse);
    
            $domnodelist = $dom->getElementsByTagName('scos');
    
            if (!empty($domnodelist->length)) {
    
    //            for ($i = 0; $i < $domnodelist->length; $i++) {
    
                    $innernodelist = $domnodelist->item(0)->getElementsByTagName('sco');
    
                    if (!empty($innernodelist->length)) {
    
                        for ($x = 0; $x < $innernodelist->length; $x++) {
    
                            if ($innernodelist->item($x)->hasAttributes()) {
    
                                $domnode = $innernodelist->item($x)->attributes->getNamedItem('sco-id');
    
                                if (!is_null($domnode)) {
                                    $meetingdetail = $innernodelist->item($x);
    
                                    // Check if the SCO item is a recording or uploaded document.  We only want to display recordings
    				//
    				// DFNVC - 24.5.2012
    				//
    				//In AC9, the recording length info is stored as an attributed of 'sco'
                                    $recordingvac9 = $innernodelist->item($x)->attributes->getNamedItem('duration');
                                    //In AC-8 and before, the recording length info is stored as its own element
                                    $recordingvac8 = $meetingdetail->getElementsByTagName('duration')->item(0);
    
                                    if (!is_null($recordingvac9) || !is_null($recordingvac8)) {
    
                                        $j = (int) $domnode->nodeValue;
                                        $value = (!is_null($meetingdetail->getElementsByTagName('name'))) ?
                                                 $meetingdetail->getElementsByTagName('name')->item(0)->nodeValue : '';
    
                                        $recordings[$j]->name = (string) $value;
    
                                        $value = (!is_null($meetingdetail->getElementsByTagName('url-path'))) ?
                                                 $meetingdetail->getElementsByTagName('url-path')->item(0)->nodeValue : '';
    
                                        $recordings[$j]->url = (string) $value;
    
                                        $value = (!is_null($meetingdetail->getElementsByTagName('date-begin'))) ?
                                                 $meetingdetail->getElementsByTagName('date-begin')->item(0)->nodeValue : '';
    
                                        $recordings[$j]->startdate = (string) $value;
    
                                        $value = (!is_null($meetingdetail->getElementsByTagName('date-end'))) ?
                                                 $meetingdetail->getElementsByTagName('date-end')->item(0)->nodeValue : '';
    
                                        $recordings[$j]->enddate = (string) $value;
    
                                        $value = (!is_null($meetingdetail->getElementsByTagName('date-created'))) ?
                                                 $meetingdetail->getElementsByTagName('date-created')->item(0)->nodeValue : '';
    
                                        $recordings[$j]->createdate = (string) $value;
    
                                        $value = (!is_null($meetingdetail->getElementsByTagName('date-modified'))) ?
                                                 $meetingdetail->getElementsByTagName('date-modified')->item(0)->nodeValue : '';
    
                                        $recordings[$j]->modified = (string) $value;
    
    				    $value = (!is_null($recordingvac9) ?
                                                 $recordingvac9->nodeValue : $recordingvac8->nodeValue);
    
                                        $recordings[$j]->duration = (string) $value;
                                    }
    
                                }
                            }
                        }
                    }
    //            }
    
                return $recordings;
            } else {
                return false;
            }
        } else {
            return false;
        }
    
    }
    
    /**
     * Parses XML and returns the meeting sco-id
     * @param string XML obtained from a sco-update call
     */
    function aconnect_get_meeting_scoid($xml) {
        $scoid = false;
    
        $dom = new DomDocument();
        $dom->loadXML($xml);
    
        $domnodelist = $dom->getElementsByTagName('sco');
    
        if (!empty($domnodelist->length)) {
            if ($domnodelist->item(0)->hasAttributes()) {
                $domnode = $domnodelist->item(0)->attributes->getNamedItem('sco-id');
    
                if (!is_null($domnode)) {
                    $scoid = (int) $domnode->nodeValue;
                }
            }
        }
    
        return $scoid;
    }
    
    /**
     * Update meeting
     * @param obj $aconnect connect_class object
     * @param obj $meetingobj an adobeconnect module object
     * @param int $meetingfdl adobe connect meeting folder sco-id
     * @return bool true if call was successful else false
     */
    function aconnect_update_meeting($aconnect, $meetingobj, $meetingfdl) {
        $params = array('action' => 'sco-update',
                        'sco-id' => $meetingobj->scoid,
                        'name' => $meetingobj->name,
                        'folder-id' => $meetingfdl,
    // updating meeting URL using the API corrupts the meeting for some reason
    //                    'url-path' => '/'.$meetingobj->meeturl,
                        'date-begin' => $meetingobj->starttime,
                        'date-end' => $meetingobj->endtime,
                        );
    
        $aconnect->create_request($params);
    
        if ($aconnect->call_success()) {
            return true;
        } else {
            return false;
        }
    
    }
    
    /**
     * Update a meeting's access permissions
     * @param obj $aconnect connect_class object
     * @param int $meetingscoid meeting sco-id
     * @param int $perm meeting permission id
     * @return bool true if call was successful else false
     */
    function aconnect_update_meeting_perm($aconnect, $meetingscoid, $perm) {
         $params = array('action' => 'permissions-update',
                         'acl-id' => $meetingscoid,
                         'principal-id' => 'public-access',
                        );
    
         switch ($perm) {
             case ADOBE_MEETPERM_PUBLIC:
                $params['permission-id'] = 'view-hidden';
                break;
             case ADOBE_MEETPERM_PROTECTED:
                $params['permission-id'] = 'remove';
                break;
             case ADOBE_MEETPERM_PRIVATE:
             default:
                $params['permission-id'] = 'denied';
                break;
         }
    
         $aconnect->create_request($params);
    
        if ($aconnect->call_success()) {
            return true;
        } else {
            return false;
        }
    
    
     }
    
    /** CONTRIB-1976, CONTRIB-1992
     * This function adds a fraction of a second to the ISO 8601 date
     * @param int $time unix timestamp
     * @return mixed a string (ISO 8601) containing the decimal fraction of a second
     * or false if it was not able to determine where to put it
     */
    function aconnect_format_date_seconds($time) {
    
        $newdate = false;
        $date = date("c", $time);
    
        $pos = strrpos($date, '-');
        $length = strlen($date);
    
        $diff = $length - $pos;
    
        if ((0 < $diff) and (ADOBE_TMZ_LENGTH == $diff)) {
            $firstpart = substr($date, 0, $pos);
            $lastpart = substr($date, $pos);
            $newdate = $firstpart . '.000' . $lastpart;
    
            return $newdate;
        }
    
        $pos = strrpos($date, '+');
        $length = strlen($date);
    
        $diff = $length - $pos;
    
        if ((0 < $diff) and (ADOBE_TMZ_LENGTH == $diff)) {
            $firstpart = substr($date, 0, $pos);
            $lastpart = substr($date, $pos);
            $newdate = $firstpart . '.000' . $lastpart;
    
            return $newdate;
    
        }
    
        return false;
    }
    
    /**
     * Creates a meeting
     * @param obj $aconnect connect_class object
     * @param obj $meetingobj an adobeconnect module object
     * @param int $meetingfdl adobe connect meeting folder sco-id
     * @return mixed meeting sco-id on success || false on error
     */
    function aconnect_create_meeting($aconnect, $meetingobj, $meetingfdl) {
        //date("Y-m-d\TH:i
    
        // DFNVC
        // Meeting soll Kurssprache übernehmen
        // 
        global $COURSE;
        $clang = $COURSE->lang;
        if (! ($clang == 'de' || $clang == 'en' || $clang =='it')) {
    	$meetinglang = 'de';
        }
        else {
    	$meetinglang = $clang;
        }
    
        $starttime = aconnect_format_date_seconds($meetingobj->starttime);
        $endtime = aconnect_format_date_seconds($meetingobj->endtime);
    
        if (empty($starttime) or empty($endtime)) {
            $message = 'Failure (aconnect_find_timezone) in finding the +/- sign in the date timezone'.
                        "\n".date("c", $meetingobj->starttime)."\n".date("c", $meetingobj->endtime);
            debugging($message, DEBUG_DEVELOPER);
            return false;
        }