*
 * Open eClass is an open platform distributed in the hope that it will
 * be useful (without any warranty), under the terms of the GNU (General
 * Public License) as published by the Free Software Foundation.
 * The full license can be read in "/info/license/license_gpl.txt".
 *
 * Contact address: GUnet Asynchronous eLearning Group,
 *                  Network Operations Center, University of Athens,
 *                  Panepistimiopolis Ilissia, 15784, Athens, Greece
 *                  e-mail: info@openeclass.org
 * ======================================================================== 
 */

session_start();
require_once '../clouddrive.php';
$drive = CloudDriveManager::getSessionDrive();

$url = trim(addslashes(array_key_exists('url', $_POST) ? $_POST['url'] : $drive->getDefaultURL()));
$username = trim(addslashes(array_key_exists('username', $_POST) ? $_POST['username'] : ""));
$password = array_key_exists('password', $_POST) ? $_POST['password'] : "";
$username_value = ($username == "")? "value='' placeholder='Username'" : "value='" . q($username) . "'";

if ($drive->checkCredentials($url, $username, $password)) {
    header('Location: ' . '../popup.php?' . $drive->getDriveDefaultParameter() . "&" . $drive->getCallbackName() . '=' . $drive->encodeCredentials($url, $username, $password));
    die();
}

echo '<head>';
echo '<title>User Login</title>';
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
echo '<meta name="viewport" content="width=device-width, initial-scale=1.0">';