示例#1
0
 /**
  * @url POST file
  * @param array $roleIds
  */
 public function fileUpload($roleIds = null)
 {
     try {
         $session = Session::singleton();
         $session->activateRoles($roleIds);
         // TODO: Check if upload is allowed in interface
         if (is_uploaded_file($_FILES['file']['tmp_name'])) {
             $tmp_name = $_FILES['file']['tmp_name'];
             $new_name = time() . '_' . $_FILES['file']['name'];
             $target = Config::get('uploadPath') . '/' . $new_name;
             $result = move_uploaded_file($tmp_name, $target);
             if ($result) {
                 Notifications::addSuccess("File '" . $new_name . "' uploaded");
             } else {
                 Notifications::addError("Error in file upload");
             }
         } else {
             Notifications::addError('No file uploaded');
         }
         $newAtom = $session->database->addAtomToConcept(Concept::createNewAtom('Upload'), 'Upload');
         $session->database->editUpdate('fileName', false, $newAtom, 'Upload', $new_name, 'FileName');
         $session->database->editUpdate('originalFileName', false, $newAtom, 'Upload', $_FILES['file']['name'], 'FileName');
         $session->database->commitTransaction();
         $result = array('notifications' => Notifications::getAll(), 'files' => $_FILES, 'uploadId' => $newAtom);
         return $result;
     } catch (Exception $e) {
         throw new RestException($e->getCode(), $e->getMessage());
     }
 }
 private static function pushNotification($userKey, $message, $title = null, $url = null, $urltitle = null)
 {
     Notifications::addLog('Pushover[pushNotification' . ']; $userKey=[' . $userKey . ']; $message=[' . $message . ']; $title=[' . $title . ']; $url=[' . $url . ']; $urltitle=[' . $urltitle . ']', 'MESSAGING');
     $notification = new Pushover();
     $token = Config::get('applicationToken', 'msg_pushover');
     if (is_null($token)) {
         throw new Exception("Pushover - Application token not specified", 500);
     }
     if (is_null($userKey)) {
         throw new Exception("Pushover - User key not specified", 500);
     }
     $notification->setToken($token);
     $notification->setUser($userKey);
     $notification->setMessage($message);
     if (!is_null($title)) {
         $notification->setTitle($title);
     }
     $notification->setHtml(1);
     $notification->setUrl($url);
     $notification->setUrlTitle($urltitle);
     if (!$notification->send()) {
         Notifications::addError("Pushover - Error in sending a notification to '{$userKey}'");
     } else {
         Notifications::addSuccess('Pushover message sent.');
     }
 }
 private static function pushNotification($userKey, $message, $title = null, $url = null, $urltitle = null)
 {
     Notifications::addLog('Pushalot - $userKey=[' . $userKey . ']; $message=[' . $message . ']; $title=[' . $title . ']; $url=[' . $url . ']; $urltitle=[' . $urltitle . ']', 'MESSAGING');
     if (is_null($userKey)) {
         throw new Exception("Pushalot - User/API key not specified", 500);
     }
     $notification = new Pushalot($userKey);
     //$pushalot->setProxy('http://localhost:12345','user:pass');
     $success = $notification->sendMessage(array('Title' => $title, 'Body' => $message, 'IsImportant' => true, 'IsSilent' => false, 'Image' => 'http://wiki.tarski.nl/skins/common/images/AmpersandLogo.png', 'Source' => 'Ampersand prototype'));
     if (!$success) {
         Notifications::addError("Pushalot error '{$notification->getError}()' sending notification to '{$userKey}'");
     } else {
         Notifications::addSuccess('Pushalot message sent.');
     }
 }
示例#4
0
function createPage($smarty)
{
    if (Users::loggedIn()) {
        Redirect::to('?page=profile');
    }
    if (Input::exists()) {
        if (Input::get('action') === 'register') {
            $validation = new Validate();
            $validation->check($_POST, array_merge(Config::get('validation/register_info'), Config::get('validation/set_password')));
            if ($validation->passed()) {
                try {
                    Users::create(array('student_id' => Input::get('sid'), 'password' => Hash::hashPassword(Input::get('password')), 'permission_group' => 1, 'name' => Input::get('name'), 'email' => Input::get('email'), 'umail' => Input::get('sid') . '@umail.leidenuniv.nl', 'phone' => Phone::formatNumber(Input::get('phone')), 'joined' => DateFormat::sql()));
                    Users::login(Input::get('sid'), Input::get('password'));
                    Notifications::addSuccess('You have been succesfully registered!');
                    Redirect::to('?page=profile');
                } catch (Exception $e) {
                    Notifications::addError($e->getMessage());
                }
            } else {
                Notifications::addValidationFail($validation->getErrors());
            }
        }
        if (Input::get('action') === 'login') {
            $validation = new Validate();
            $validation->check($_POST, Config::get('validation/login'));
            if ($validation->passed()) {
                $login = Users::login(Input::get('sid'), Input::get('password'), Input::getAsBool('remember'));
                if ($login) {
                    Notifications::addSuccess('You have been logged in!');
                    Redirect::to('?page=profile');
                } else {
                    Notifications::addValidationFail('Invalid student number or password.');
                }
            } else {
                Notifications::addValidationFail($validation->getErrors());
            }
        }
    }
    $smarty->assign('remember', Input::getAsBool('remember'));
    $smarty->assign('name', Input::get('name'));
    $smarty->assign('sid', Input::get('sid'));
    $smarty->assign('email', Input::get('email'));
    $smarty->assign('phone', Input::get('phone'));
    return $smarty;
}
示例#5
0
function SendEmail($to, $subject, $message)
{
    // adapted from http://phpmailer.worxware.com/?pg=examplebgmail
    $config = Config::get('sendEmailConfig', 'execEngine');
    $from = $config['from'];
    $username = $config['username'];
    $password = $config['password'];
    Notifications::addLog('Username = '******'ExecEngine');
    $mail = new PHPMailer();
    $mail->IsSMTP();
    // Set mailer to use SMTP
    // $mail->SMTPDebug = 1;
    $mail->Host = 'smtp.gmail.com';
    // Specify main and backup server
    $mail->SMTPSecure = 'tls';
    // Enable encryption, 'ssl' also accepted
    $mail->Port = 587;
    $mail->SMTPAuth = true;
    // Enable SMTP authentication
    $mail->Username = $username;
    // SMTP username (for GMAIL)
    $mail->Password = $password;
    // SMTP password
    $mail->From = $from;
    $mail->FromName = 'Ampersand Prototype';
    $mail->AddAddress($to);
    // Add a recipient, e.g. $to = '*****@*****.**', 'Rieks Joosten'
    $mail->Subject = $subject;
    $mail->Body = $message;
    $mail->WordWrap = 50;
    // Set word wrap to 50 characters
    if (!$mail->Send()) {
        Notifications::addError('Mailer Error: ' . $mail->ErrorInfo);
    } else {
        Notifications::addSuccess('Email message sent.');
    }
}
示例#6
0
 public function closeTransaction($succesMessage = 'Updated', $checkAllConjucts = true, $databaseCommit = false, $setNewContent = true)
 {
     $session = Session::singleton();
     Hooks::callHooks('preDatabaseCloseTransaction', get_defined_vars());
     Notifications::addLog('========================= CLOSING TRANSACTION =========================', 'DATABASE');
     if ($checkAllConjucts) {
         Notifications::addLog("Check all conjuncts", 'DATABASE');
         // Evaluate all invariant conjuncts. Conjuncts are cached.
         $invariantRulesHold = RuleEngine::checkInvariantRules();
         // Evaluate all signal conjuncts. Conjuncts are cached
         RuleEngine::checkProcessRules();
     } else {
         Notifications::addLog("Check all affected conjuncts", 'DATABASE');
         // Evaluate all affected invariant conjuncts. Conjuncts are cached.
         $invariantRulesHold = RuleEngine::checkInvariantRules(RuleEngine::getAffectedInvConjuncts($this->affectedConcepts, $this->affectedRelations), true);
         // Evaluate all affected signal conjuncts. Conjuncts are cached
         RuleEngine::checkConjuncts(RuleEngine::getAffectedSigConjuncts($this->affectedConcepts, $this->affectedRelations), true);
         // Check only those process rules that are relevant for the activate roles
         RuleEngine::checkProcessRules($session);
     }
     unset($this->affectedConcepts, $this->affectedRelations);
     $this->affectedConcepts = array();
     $this->affectedRelations = array();
     if ($setNewContent && isset($session->atom)) {
         $session->atom->setNewContent($session->interface);
     }
     // e.g. not needed in Atom::delete() function
     if ($invariantRulesHold && $databaseCommit) {
         $this->commitTransaction();
         // commit database transaction
         Notifications::addSuccess($succesMessage);
     } elseif (Config::get('ignoreInvariantViolations', 'transactions') && COMMIT_INV_VIOLATIONS) {
         $this->commitTransaction();
         Notifications::addError("Transaction committed with invariant violations");
     } elseif ($invariantRulesHold) {
         $this->rollbackTransaction();
         // rollback database transaction
         Notifications::addInfo($succesMessage);
     } else {
         $this->rollbackTransaction();
         // rollback database transaction
     }
     Hooks::callHooks('postDatabaseCloseTransaction', get_defined_vars());
     return $invariantRulesHold;
 }
示例#7
0
function createPage($smarty)
{
    if (!Users::loggedIn()) {
        Redirect::to('?page=login');
    }
    if (Input::exists()) {
        if (Input::get('action') === 'logout') {
            if (Users::loggedIn()) {
                Users::logout();
                Notifications::addSuccess('You have been logged out!');
                Redirect::to('?page=login');
            }
        }
        if (Input::get('action') === 'update_info') {
            $validation = new Validate();
            $validation->check($_POST, Config::get('validation/user_info'));
            if ($validation->passed()) {
                $data = array('name' => Input::get('name'), 'student_id' => Input::get('sid'), 'email' => Input::get('email'), 'phone' => Phone::formatNumber(Input::get('phone')));
                if (Users::currentUser()->update($data)) {
                    Notifications::addSuccess('User information updated!');
                } else {
                    Notifications::addError('Could not update user information.');
                }
            } else {
                Notifications::addValidationFail($validation->getErrors());
            }
        }
        if (Input::get('action') === 'update_pass') {
            $validation = new Validate();
            $validation->check($_POST, array_merge(Config::get('validation/set_password'), array('password_current' => array('name' => 'Current Password', 'required' => true, 'max' => 72))));
            if ($validation->passed()) {
                if (Hash::checkPassword(Input::get('password_current'), Users::currentData()->password)) {
                    if (Users::currentUser()->update(array('password' => Hash::hashPassword(Input::get('password'))))) {
                        Notifications::addSuccess('Password changed!');
                    } else {
                        Notifications::addError('Could not change password.');
                    }
                } else {
                    Notifications::addValidationFail('Invalid current password.');
                }
            } else {
                Notifications::addValidationFail($validation->getErrors());
            }
        }
        if (Input::get('action') === 'update_googleAuth') {
            $validation = new Validate();
            $validation->check($_POST, array('authcode' => array('name' => 'Authorisation Code', 'required' => true)));
            if ($validation->passed()) {
                if (Calendar::setCredentials(Input::get('authcode'))) {
                    Notifications::addSuccess('Google Calendar API authorized!');
                } else {
                    Notifications::addValidationFail('Could not authorize Google Calendar API.');
                }
            } else {
                Notifications::addValidationFail($validation->getErrors());
            }
        }
        if (Input::get('action') === 'update_calendarAssignmentsId') {
            $validation = new Validate();
            $validation->check($_POST, array('calid-ass' => array('name' => 'Assignments Calendar ID', 'required' => false), 'calid-ex' => array('name' => 'Exams Calendar ID', 'required' => false)));
            if ($validation->passed()) {
                $data = array('calendar_assignments' => Input::get('calid-ass'), 'calendar_exams' => Input::get('calid-ex'));
                if (Users::currentUser()->update($data)) {
                    Notifications::addSuccess('Calendar ID\'s updated!');
                } else {
                    Notifications::addValidationFail('Could not update calendar ID\'s.');
                }
            } else {
                Notifications::addValidationFail($validation->getErrors());
            }
        }
        if (Input::get('action') === 'delete_googleAuth') {
            Calendar::deleteCredentials();
        }
        if (Input::get('action') === 'update_calendarAssignments' && Users::isEditor()) {
            $assignments = DB::instance()->get(Users::safeSid() . "_assignments")->results();
            foreach ($assignments as $assignment) {
                Calendar::updateAssignment($assignment->id);
            }
        }
        if (Input::get('action') === 'create_database') {
            if (!UserTables::hasTables()) {
                UserTables::createTables();
                if (Users::isGuest()) {
                    Users::currentUser()->update(array('permission_group' => '2'));
                }
            }
        }
    }
    if (!Calendar::isReady()) {
        $smarty->assign('authUrl', Calendar::getAuthUrl());
    }
    $smarty->assign('authCode', Input::get('authcode'));
    $smarty->assign('calid_ass', Users::currentData()->calendar_assignments);
    $smarty->assign('calid_ex', Users::currentData()->calendar_exams);
    $smarty->assign('name', Users::currentData()->name);
    $smarty->assign('sid', Users::currentData()->student_id);
    $smarty->assign('email', Users::currentData()->email);
    $smarty->assign('phone', Users::currentData()->phone);
    return $smarty;
}
 private static function pushNotification($emailAddr, $message, $title = null, $url = null, $urltitle = null)
 {
     Notifications::addLog('Email[pushNotification' . ']; $emailAddr=[' . $emailAddr . ']; $message=[' . $message . ']; $title=[' . $title . ']; $url=[' . $url . ']; $urltitle=[' . $urltitle . ']', 'MESSAGING');
     // adapted from http://phpmailer.worxware.com/?pg=examplebgmail
     $config = Config::get('sendEmailConfig', 'msg_email');
     $from = $config['from'];
     $username = $config['username'];
     $password = $config['password'];
     Notifications::addLog('Email.php - Username = '******'MESSAGING');
     $mail = new PHPMailer();
     $mail->IsSMTP();
     // Set mailer to use SMTP
     // $mail->SMTPDebug = 1;
     $mail->Host = 'smtp.gmail.com';
     // Specify main and backup server
     $mail->SMTPSecure = 'ssl';
     // Enable encryption, 'ssl' also accepted
     $mail->Port = 465;
     $mail->SMTPAuth = true;
     // Enable SMTP authentication
     $mail->Username = $username;
     // SMTP username (for GMAIL)
     $mail->Password = $password;
     // SMTP password
     $mail->From = $from;
     $mail->FromName = 'Ampersand Prototype';
     $mail->AddAddress($emailAddr);
     // Add a recipient, e.g. $to = '*****@*****.**', 'Rieks Joosten'
     $mail->Subject = $title;
     //      $message = $message . 'optional URL';
     if ($url != '_NULL' && $url != '') {
         $mail->IsHTML(true);
         // make sure we send in HTML
         if ($urltitle != '_NULL' && $urltitle != '') {
             $message = '<p>' . $message . '</p><p><a href=' . $url . '>' . $urltitle . '</a></p>';
         } else {
             $message = $message . '<a' . $urltitle . '</a>';
         }
         Notifications::addLog('Email message refactored to: [' . $message . ']', 'MESSAGING');
     }
     $mail->Body = $message;
     $mail->WordWrap = 50;
     // Set word wrap to 50 characters
     if (!$mail->Send()) {
         Notifications::addError('Mailer Error: ' . $mail->ErrorInfo);
     } else {
         Notifications::addSuccess('Email message sent.');
     }
 }
示例#9
0
 private static function pushNotification($SMSAddr, $message, $title = null, $url = null, $urltitle = null)
 {
     Notifications::addLog('UNTESTED !!! SMS[pushNotification' . ']; $SMSAddr=[' . $SMSAddr . ']; $message=[' . $message . ']; $title=[' . $title . ']; $url=[' . $url . ']; $urltitle=[' . $urltitle . ']', 'MESSAGING');
     /* Config params for SendSMS function of ExecEngine (using MessageBird.com)
      * Set the sender, could be a number (16 numbers) or letters (11 characters)
      * 
      */
     // Copy the following line to localSettings.php and provide settings
     // Config::set('sendSMSConfig', 'execEngine', array('username' => '', 'password' => '', 'sender' => ''));
     $config = Config::get('sendSMSConfig', 'msg_SMS');
     $username = $config['username'];
     $password = $config['password'];
     $sender = $config['sender'];
     Notifications::addLog('Username = '******'MESSAGING');
     // Set the Messagebird username and password, and create an instance of the MessageBird class
     $sms = new MessageBird($username, $password);
     // Set the sender, could be a number (16 numbers) or letters (11 characters)
     $sms->setSender($sender);
     // Add the destination mobile number.
     // This method can be called several times to add have more then one recipient for the same message
     $sms->addDestination($SMSAddr);
     //e.g. $sms->addDestination('31600000000');
     // Set an reference, optional
     // $sms->setReference('123456789');
     // Set a schedule date-time, optional
     // $sms->setTimestamp('2014-01-01 10:02');
     // Replace non GSM-7 characters by appropriate valid GSM-7 characters
     // $sms->setReplacechars(false);
     // If you want a dlr notification of the message send to another url then that you have set on the web site, you can use this parameter. Don't forget to set a reference!
     // $sms->setDlrUrl('http://www.example.com/dlr_url.php');
     // If $test is TRUE, then the message is not actually sent or scheduled, and there will be no credits deducted.
     Notifications::addLog("SMS testing is set to TRUE (messages are not actually sent)", 'MESSAGING');
     $sms->setTest(true);
     // Send the message to the destination(s)
     $sms->sendSms($message);
     if ($sms->getResponseCode() == "01") {
         Notifications::addSuccess('SMS message sent.');
     } else {
         Notifications::addError('SMS error: ' . $sms->getResponseMessage());
     }
     Notifications::addLog("SMS Response: " . $sms->getResponseMessage(), 'MESSAGING');
     Notifications::addLog("SMS Balance: " . $sms->getCreditBalance(), 'MESSAGING');
 }
示例#10
0
 public static function deleteAssignment($id)
 {
     if (Users::loggedIn() && self::isReady()) {
         $service = self::getService();
         $eventId = Users::currentData()->student_id . 'assignment' . $id;
         $calendarId = Users::currentData()->calendar_assignments;
         $service->events->delete($calendarId, $eventId);
         Notifications::addSuccess('Google calendar event deleted!');
     }
 }
示例#11
0
 public static function adminDeleteItem()
 {
     if (Users::isAdmin()) {
         $validation = new Validate();
         $validation->check($_POST, array('action' => array('name' => 'Action', 'required' => true, 'wildcard' => 'admin_item_delete'), 'table' => array('name' => 'Table Name', 'required' => true), 'id' => array('name' => 'Entry ID', 'required' => true)));
         if ($validation->passed()) {
             DB::instance()->delete(Input::get('table'), array("", "id", "=", Input::get('id')));
             if (Input::get('table') === Users::safeSid() . '_assignments') {
                 Calendar::deleteAssignment(Input::get('id'));
             }
             Notifications::addSuccess('Entry deleted!');
             Redirect::to('?page=home');
         } else {
             Notifications::addValidationFail($validation->getErrors());
         }
     } else {
         Redirect::error(403);
     }
 }