Example #1
0
 /**
  * Sign request with private key
  * 
  * @param Request request
  */
 function signRequest(Request $request)
 {
     $request->set('clientId', $this->clientId);
     $params = $request->getParameters();
     ksort($params);
     $token = $this->privateKey;
     foreach ($params as $key => $value) {
         $token .= $key . $value;
     }
     $request->set('hash', hash('sha256', $token));
 }
Example #2
0
 public function testSetParam()
 {
     Request::set('yyy', 'xyzzy');
     Request::set('zzz', array(1, 2));
     $this->assertSame(Request::get('yyy'), 'xyzzy');
     $this->assertSame(Request::getArray('zzz'), array(1, 2));
 }
Example #3
0
 function before_filter(&$action, &$args)
 {
     if (Request::option('auswahl')) {
         Request::set('cid', Request::option('auswahl'));
     }
     parent::before_filter($action, $args);
     checkObject();
     $this->institute = Institute::findCurrent();
     if (!$this->institute) {
         throw new CheckObjectException(_('Sie haben kein Objekt gewählt.'));
     }
     $this->institute_id = $this->institute->id;
     //set visitdate for institute, when coming from meine_seminare
     if (Request::option('auswahl')) {
         object_set_visit($this->institute_id, "inst");
     }
     //gibt es eine Anweisung zur Umleitung?
     if (Request::get('redirect_to')) {
         $query_parts = explode('&', stristr(urldecode($_SERVER['QUERY_STRING']), 'redirect_to'));
         list(, $where_to) = explode('=', array_shift($query_parts));
         $new_query = $where_to . '?' . join('&', $query_parts);
         page_close();
         $new_query = preg_replace('/[^:0-9a-z+_\\-.#?&=\\/]/i', '', $new_query);
         header('Location: ' . URLHelper::getURL($new_query, array('cid' => $this->institute_id)));
         die;
     }
     PageLayout::setHelpKeyword("Basis.Einrichtungen");
     PageLayout::setTitle($this->institute->getFullName() . " - " . _("Kurzinfo"));
     Navigation::activateItem('/course/main/info');
 }
Example #4
0
 public function send()
 {
     Request::post('http://api.postmarkapp.com/email', $this->parseData());
     Request::set(CURLOPT_HTTPHEADER, $this->headers);
     $return = Request::send();
     return isset($return->data) ? $return->data : $return;
 }
Example #5
0
 public static function run($routeArgs = [])
 {
     self::$routeArgs = $routeArgs;
     //URL结构处理
     $param = array_filter(explode('/', Request::get(c('http.url_var'))));
     switch (count($param)) {
         case 2:
             array_unshift($param, c('http.default_module'));
             break;
         case 1:
             array_unshift($param, c('http.default_controller'));
             array_unshift($param, c('http.default_module'));
             break;
         case 0:
             array_unshift($param, c('http.default_action'));
             array_unshift($param, c('http.default_controller'));
             array_unshift($param, c('http.default_module'));
             break;
     }
     Request::set('get.' . c('http.url_var'), implode('/', $param));
     $param[1] = preg_replace_callback('/_([a-z])/', function ($matches) {
         return ucfirst($matches[1]);
     }, $param[1]);
     define('MODULE', $param[0]);
     define('CONTROLLER', ucfirst($param[1]));
     define('ACTION', $param[2]);
     define('MODULE_PATH', ROOT_PATH . '/' . c('app.path') . '/' . MODULE);
     define('VIEW_PATH', MODULE_PATH . '/' . 'view');
     define('__VIEW__', __ROOT__ . '/' . c('app.path') . '/' . MODULE . '/view');
     self::action();
 }
Example #6
0
 /**
  * Overwritten constructor of the controller. Ensures no cid
  * is present the request.
  *
  * @param Trails_Dispatcher $dispatcher
  */
 public function __construct($dispatcher)
 {
     if (Request::get('cid')) {
         Request::set('cid', null);
     }
     parent::__construct($dispatcher);
 }
Example #7
0
 public function offsetUnset($offset)
 {
     unset($this->array[$offset]);
     foreach ($this->arrays as $array) {
         unset($array[$offset]);
     }
     $this->req->set($offset, null);
 }
  function testGetRequestedActionOkActionFound()
  {
    $resolver = new ActionRequestResolver();

    $request = new Request();
    $request->set('action', $action = 'whatever');

    $this->assertEqual($resolver->resolve($request), $action);
  }
 public function testControllerWithXmlHttpRequest()
 {
     $request = new Request();
     $request->set('q', 'Hello');
     $request->setRequestFormat('XmlHttpRequest');
     $ctrl = new SearchController();
     $response = $ctrl->searchAction($request);
     $this->assertEquals('ProductBundle:Search:list.html.twig{"products":{"0":{"name":"foo","description":"A foo product","price":42},"1":{"name":"bar","description":"A bar product","price":23}},"noLayout":true}', $response->getContent());
 }
Example #10
0
 public function testShoudGetParams()
 {
     $_GET = ['city' => 'city A'];
     $this->assertEquals(['paginate' => false, 'page' => 1, 'offset' => $this->object->getDefaultOffset(), 'filter' => ['city' => ['=' => ['city A']]], 'embed' => [], 'sort' => [], 'search' => ''], $this->object->params());
     $this->object->set('add', ['city' => 'city B']);
     $this->assertEquals(['paginate' => false, 'page' => 1, 'offset' => $this->object->getDefaultOffset(), 'filter' => ['city' => ['=' => ['city A', 'city B']]], 'embed' => [], 'sort' => [], 'search' => ''], $this->object->params());
     // passing true should discart changes made with 'set'
     $this->assertEquals(['paginate' => false, 'page' => 1, 'offset' => $this->object->getDefaultOffset(), 'filter' => ['city' => ['=' => ['city A']]], 'embed' => [], 'sort' => [], 'search' => ''], $this->object->params(true));
 }
Example #11
0
 public static function send($data)
 {
     // Get the config information
     $pm = Config::get('email.postmark');
     $key = $pm['apiKey'];
     //  Set headers to send to Postmark
     $headers = array('Accept: application/json', 'Content-Type: application/json', 'X-Postmark-Server-Token: ' . $key);
     Request::post('http://api.postmarkapp.com/email', json_encode($data));
     Request::set(CURLOPT_HTTPHEADER, $headers);
     $return = Request::send();
     return $return;
 }
Example #12
0
 public function route(Request $request)
 {
     $parts = explode('/', $request->getServer('REQUEST_URI'));
     unset($parts[0]);
     $controller = array_shift($parts);
     if (!isset($this->values[$controller])) {
         throw new RouterException();
     }
     if (count($parts) % 2 != 0) {
         throw new RouterException();
     }
     $keys = array_keys($parts);
     $count = count($keys);
     for ($i = 0; $i < $count; $i += 2) {
         $request->set($parts[$keys[$i]], $parts[$keys[$i + 1]]);
     }
     return $this->values[$controller];
 }
Example #13
0
 public function before_filter(&$action, &$args)
 {
     parent::before_filter($action, $args);
     PageLayout::setHelpKeyword("Basis.VeranstaltungenAbonnieren");
     PageLayout::setTitle(_("Veranstaltungssuche"));
     if (Request::option('view')) {
         $_SESSION['sem_portal']['bereich'] = Request::option('view');
     }
     if (!$_SESSION['sem_portal']['bereich']) {
         $_SESSION['sem_portal']['bereich'] = "all";
     }
     Request::set('view', $_SESSION['sem_portal']['bereich']);
     Navigation::activateItem('/search/courses/' . $_SESSION['sem_portal']['bereich']);
     if (Request::option('choose_toplist')) {
         $_SESSION['sem_portal']['toplist'] = Request::option('choose_toplist');
     }
     if (!$_SESSION['sem_portal']['toplist']) {
         $_SESSION['sem_portal']['toplist'] = 4;
     }
 }
Example #14
0
 public function index_action()
 {
     if (Request::option('select_sem_id')) {
         Request::set('cid', Request::option('select_sem_id'));
     }
     PageLayout::setTitle("Teilnehmerverwaltung - " . $this->seminar->getName());
     $this->users = $this->seminar->getMembers('autor');
     $this->tutors = $this->seminar->getMembers('tutor');
     //$this->set_layout('layouts/base.php');
     $this->display = isset($GLOBALS['SessSemName'][1]);
     $this->name = $GLOBALS['SessSemName'][0];
     $this->refered_from_seminar = $_SESSION['links_admin_data']['referred_from'] === 'sem';
     $response = $this->relay("show/searchForm");
     $this->search_form = $response->body;
     global $auth, $perm, $user;
     $this->msg = $msg;
     $this->auth = $auth;
     $this->db = $db;
     $this->user = $user;
 }
Example #15
0
 public function loadRequestModel(Request $request, $key = '')
 {
     $json = $request->getJSON();
     if ($key) {
         $json = $json[$key];
     }
     $modelReq = new Request();
     $modelReq->setValueArray($json);
     if (!empty($json['attributes']) && is_array($json['attributes'])) {
         foreach ($json['attributes'] as $key => $value) {
             if (!empty($value['valueIDs'])) {
                 foreach (json_decode($value['valueIDs']) as $valueID) {
                     $modelReq->set('specItem_' . $valueID, 'on');
                 }
                 if (!empty($value['newValues'])) {
                     foreach (json_decode($value['newValues']) as $newVal) {
                         $others = $modelReq->get('other', array());
                         $others[$key][] = $newVal;
                         $modelReq->set('other', $others);
                     }
                 }
                 $modelReq->set('removeEmpty_' . $key, 'on');
             } else {
                 if (isset($value['ID'])) {
                     $modelReq->set('specField_' . $key, $value['ID']);
                     if (!empty($value['newValue'])) {
                         $others = $modelReq->get('other', array());
                         $others[$key] = $value['newValue'];
                         $modelReq->set('other', $others);
                     }
                 } else {
                     $modelReq->set('specField_' . $key, $value['value']);
                     foreach (self::getApplication()->getLanguageArray() as $lang) {
                         if (!empty($value['value_' . $lang])) {
                             $modelReq->set('specField_' . $key . '_' . $lang, $value['value_' . $lang]);
                         }
                     }
                 }
             }
         }
     }
     $this->loadRequestData($modelReq);
 }
Example #16
0
 public function makeRoute($routeInputString)
 {
     $defaultRouteArr = explode("/", preg_replace('/^\\/|\\/$/', "", $this->defaultRoute));
     $requestRoute = explode("/", preg_replace('/^\\/|\\/$/', "", $routeInputString));
     for ($i = 0; $i < count($defaultRouteArr); $i++) {
         switch ($defaultRouteArr[$i]) {
             case ':module:':
                 $this->module = $requestRoute[$i];
                 break;
             case ':controller:':
                 $this->controller = empty($requestRoute[$i]) ? "index" : $requestRoute[$i];
                 break;
             case ':action:':
                 $this->action = empty($requestRoute[$i]) ? "index" : $requestRoute[$i];
                 break;
             default:
                 throw new Exception("Bad route configuration");
         }
     }
     unset($i);
     $key = null;
     $value = null;
     for ($i = count($defaultRouteArr); $i < count($requestRoute); $i++) {
         if ($key === null) {
             $key = $requestRoute[$i];
             if (!isset($_POST[$key])) {
                 Request::set($key, "");
             }
         } else {
             if ($value === null) {
                 $value = $requestRoute[$i];
                 if (!isset($_POST[$key])) {
                     Request::set($key, $value);
                 }
                 $key = $value = null;
             }
         }
     }
 }
Example #17
0
 function StudipSemSearch($form_name = "search_sem", $auto_search = true, $visible_only = false, $sem_class = 'all')
 {
     $search_fields = array('title' => array('type' => 'text'), 'sub_title' => array('type' => 'text'), 'number' => array('type' => 'text'), 'comment' => array('type' => 'text'), 'lecturer' => array('type' => 'text'), 'scope' => array('type' => 'text'), 'quick_search' => array('type' => 'text'), 'type' => array('type' => 'select', 'default_value' => 'all', 'max_length' => 35, 'options_callback' => array($this, 'getSelectOptions')), 'sem' => array('type' => 'select', 'default_value' => 'all', 'options_callback' => array($this, 'getSelectOptions')), 'category' => array('type' => 'select', 'default_value' => 'all', 'max_length' => 50, 'options_callback' => array($this, 'getSelectOptions')), 'combination' => array('type' => 'select', 'default_value' => 'AND', 'options_callback' => array($this, 'getSelectOptions')), 'scope_choose' => array('type' => 'select', 'default_value' => 'root', 'max_length' => 45, 'options_callback' => array($this, 'getSelectOptions')), 'range_choose' => array('type' => 'select', 'default_value' => 'root', 'max_length' => 45, 'options_callback' => array($this, 'getSelectOptions')), 'qs_choose' => array('type' => 'select', 'default_value' => 'title_lecturer_number', 'options_callback' => array($this, 'getSelectOptions')));
     $search_buttons = array('do_search' => array('caption' => _("Suchen"), 'info' => _("Suche starten")), 'sem_change' => array('caption' => _('Auswählen'), 'info' => _("anderes Semester auswählen")), 'new_search' => array('caption' => _('Neue Suche'), 'info' => _("Neue Suche starten")));
     //workaround: Qicksearch ändert den Namen des Eingabefeldes
     if (Request::get("search_sem_quick_search_parameter")) {
         Request::set('search_sem_quick_search', Request::get("search_sem_quick_search_parameter"));
     }
     $this->form = new StudipForm($search_fields, $search_buttons, $form_name, false);
     $this->form_name = $form_name;
     $this->sem_dates = SemesterData::GetSemesterArray();
     $this->visible_only = $visible_only;
     $this->search_sem_class = $sem_class;
     if ($this->form->isClicked('do_search') || $this->form->isSended() && (!$this->form->isClicked('sem_change') || strlen($this->form->getFormFieldValue('quick_search')) > 2)) {
         $this->search_button_clicked = true;
         if ($auto_search) {
             $this->doSearch();
             $this->search_done = true;
         }
     }
     $this->new_search_button_clicked = $this->form->isClicked('new_search');
     $this->sem_change_button_clicked = $this->form->isClicked('do_search');
 }
Example #18
0
 public function exec($key)
 {
     //匿名函数
     if ($this->route[$key]['callback'] instanceof Closure) {
         //反射分析闭包
         $reflectionFunction = new \ReflectionFunction($this->route[$key]['callback']);
         $gets = $this->route[$key]['get'];
         $args = [];
         foreach ($reflectionFunction->getParameters() as $k => $p) {
             if (isset($gets[$p->name])) {
                 //如果GET变量中存在则将GET变量值赋予,也就是说GET优先级高
                 $args[$p->name] = $gets[$p->name];
             } else {
                 //如果类型为类时分析类
                 if ($dependency = $p->getClass()) {
                     $args[$p->name] = App::build($dependency->name);
                 } else {
                     //普通参数时获取默认值
                     $args[$p->name] = App::resolveNonClass($p);
                 }
             }
         }
         echo $reflectionFunction->invokeArgs($args);
     } else {
         //设置控制器与方法
         Request::set('get.' . c('http.url_var'), $this->route[$key]['callback']);
         Controller::run($this->route[$key]['get']);
     }
 }
Example #19
0
 /**
  * Applies all registered filters sequentialy to a value
  *
  */
 public function filter()
 {
     foreach ($this->filterList as $filter) {
         $this->request->set($this->varName, $filter->apply($this->request->get($this->varName)));
     }
 }
 public function loadRequestData(Request $request, $prefix = '')
 {
     $fields = $this->getSpecificationFieldSet();
     $application = ActiveRecordModel::getApplication();
     // create new select values
     if ($request->isValueSet($prefix . 'other')) {
         foreach ($request->get($prefix . 'other') as $fieldID => $values) {
             $field = call_user_func_array(array($this->getFieldClass(), 'getInstanceByID'), array($fieldID, ActiveRecordModel::LOAD_DATA));
             if (is_array($values)) {
                 // multiple select
                 foreach ($values as $value) {
                     if ($value) {
                         $fieldValue = $field->getNewValueInstance();
                         $fieldValue->setValueByLang('value', $application->getDefaultLanguageCode(), $value);
                         $fieldValue->save();
                         $request->set($prefix . 'specItem_' . $fieldValue->getID(), 'on');
                     }
                 }
             } else {
                 // single select
                 if ('other' == $request->get($prefix . 'specField_' . $fieldID)) {
                     $fieldValue = $field->getNewValueInstance();
                     $fieldValue->setValueByLang('value', $application->getDefaultLanguageCode(), $values);
                     $fieldValue->save();
                     $request->set($prefix . 'specField_' . $fieldID, $fieldValue->getID());
                 }
             }
         }
     }
     $languages = ActiveRecordModel::getApplication()->getLanguageArray(LiveCart::INCLUDE_DEFAULT);
     foreach ($fields as $field) {
         $fieldName = $prefix . $field->getFormFieldName();
         if ($field->isSelector()) {
             if (!$field->isMultiValue->get()) {
                 if ($request->isValueSet($fieldName) && !in_array($request->get($fieldName), array('other'))) {
                     if ($request->get($fieldName)) {
                         $this->setAttributeValue($field, $field->getValueInstanceByID($request->get($fieldName), ActiveRecordModel::LOAD_DATA));
                     } else {
                         $this->removeAttribute($field);
                     }
                 }
             } else {
                 $values = $field->getValuesSet();
                 foreach ($values as $value) {
                     if ($request->isValueSet($prefix . $value->getFormFieldName()) || $request->isValueSet($prefix . 'checkbox_' . $value->getFormFieldName())) {
                         if ($request->get($prefix . $value->getFormFieldName())) {
                             $this->setAttributeValue($field, $value);
                         } else {
                             $this->removeAttributeValue($field, $value);
                         }
                     }
                 }
             }
         } else {
             if ($request->isValueSet($fieldName)) {
                 if ($field->isTextField()) {
                     foreach ($languages as $language) {
                         if ($request->isValueSet($prefix . $field->getFormFieldName($language))) {
                             $this->setAttributeValueByLang($field, $language, $request->get($prefix . $field->getFormFieldName($language)));
                         }
                     }
                 } else {
                     if (strlen($request->get($fieldName))) {
                         $this->setAttributeValue($field, $request->get($fieldName));
                     } else {
                         $this->removeAttribute($field);
                     }
                 }
             }
         }
     }
 }
Example #21
0
echo "<tr><td class=\"blank\" colspan=\"2\">&nbsp;</td></tr>\n";
if (Request::option('com') != "info") {
    echo "<tr><td class=\"blank\" align=\"center\" valign=\"top\" width=\"90%\">\n";
} else {
    echo "<tr><td class=\"blank\" align=\"center\" valign=\"top\" width=\"90%\" colspan=\"2\">\n";
}
echo "<table width=\"100%\" cellpadding=\"5\" cellspacing=\"0\" border=\"0\">\n";

// copy existing configuration
if (Request::option('com') == 'copyconfig') {
    if (Request::option('copyinstid') && Request::option('copyconfigid')) {
        $config = ExternConfig::GetInstance(Request::option('copyinstid'), '', Request::option('copyconfigid'));
        $config_copy = $config->copy($range_id);
        my_msg(sprintf(_("Die Konfiguration wurde als \"%s\" nach Modul \"%s\" kopiert."), htmlReady($config_copy->getConfigName()), htmlReady($GLOBALS['EXTERN_MODULE_TYPES'][$config_copy->getTypeName()]['name'])), 'blank', 1, false);
    } else {
        Request::set('com','');
    }
}

if (Request::option('com') == 'delete') {
    $config = ExternConfig::GetInstance($range_id, '', $config_id);
    if ($config->deleteConfiguration()) {
        my_msg(sprintf(_("Konfiguration <strong>\"%s\"</strong> für Modul <strong>\"%s\"</strong> gelöscht!"), htmlReady($config->getConfigName()), htmlReady($GLOBALS['EXTERN_MODULE_TYPES'][$config->getTypeName()]['name'])), 'blank', 1, false);
    } else {
        my_error(_("Konfiguration konnte nicht gelöscht werden"));
    }
}

echo "<tr><td class=\"blank\" width=\"100%\" valign=\"top\">\n";

if (Request::option('com') == 'delete_sec') {
Example #22
0
 function _search($columns = array(), $sfld = 'srch', $type = 'like')
 {
     $model_class = !empty($this->search_model) ? $this->search_model : null;
     if (empty($model_class)) {
         $alias = $this->get_main_model();
         if (!empty($alias)) {
             $model_class = $this->{$alias};
         } else {
             return false;
         }
     }
     $prefix = '';
     if (!empty($this->search_prefix)) {
         $prefix = '.' . $this->search_prefix;
     }
     if (empty($sfld) or empty($columns)) {
         return false;
     }
     $session = Base::getSession();
     $search_string = Request::data($sfld, $session->get(get_class($this) . $prefix . '.' . $model_class->alias . '.search.' . $sfld, null));
     //check if we have any search fields
     if (empty($search_string)) {
         $session->clear(get_class($this) . $prefix . '.' . $model_class->alias . '.search.' . $sfld);
         return false;
     }
     $keywords = $search_string;
     if (is_string($search_string)) {
         $must_pat = '/("|\')(.*?)("|\')/i';
         preg_match_all($must_pat, $search_string, $must_words);
         if (!empty($must_words[2])) {
             $search_string_new = preg_replace($must_pat, '', $search_string);
             $keywords = array_filter(explode(' ', $search_string_new));
             $must_keywords = $must_words[2];
         } else {
             $keywords = explode(' ', $search_string);
         }
     }
     $conditions = array();
     //build the main model's conditions
     if ($type == 'like') {
         foreach ($keywords as $keyword) {
             foreach ($columns as $k => $column) {
                 $conditions['OR'][][$column . ' LIKE'] = '%' . $keyword . '%';
             }
         }
         if (!empty($must_keywords)) {
             foreach ($must_keywords as $must_keyword) {
                 foreach ($columns as $k => $column) {
                     //$conditions['AND'][][$column.' LIKE'] = '%'.$must_keyword.'%';
                     $conditions['OR'][][$column . ' LIKE'] = '%' . $must_keyword . '%';
                 }
             }
         }
     } else {
         if ($type == 'match') {
             $columns = array_map(array($model_class->dbo, 'quoteName'), $columns);
             //$fixed_search_string = '+'.str_replace(' ', ' +', trim($search_string));
             //$conditions[] = ':MATCH ('.implode(',', $columns).') AGAINST ('.$model_class->dbo->quote($fixed_search_string).' IN BOOLEAN MODE)';
             $conditions[] = ':MATCH (' . implode(',', $columns) . ') AGAINST (' . $model_class->dbo->quote($search_string) . ' IN BOOLEAN MODE)';
         }
     }
     //set search fields values
     Request::set($sfld, $search_string);
     //set model conditions based on filters
     $model_class->conditions = array_merge($conditions, $model_class->conditions);
     $session->set(get_class($this) . $prefix . '.' . $model_class->alias . '.search.' . $sfld, $search_string);
 }
Example #23
0
 public static function page($alias = '')
 {
     $page = \GCore\Controllers\Pages::_find($alias);
     if (!empty($page)) {
         Request::set('_Route.page', $page['Page']);
         //set page title
         if ((bool) Base::getConfig('append_page_title', 1) === true) {
             $doc = Document::getInstance();
             $doc->setTitle($page['Page']['title']);
         }
         //pass more page params
         Request::set('_Route.index', $page['Page']['id']);
         if ($page['Page']['default'] == 1) {
             Request::set('_Route.default', 1);
         }
         $params = array('extension' => $page['Page']['extension'], 'controller' => $page['Page']['controller'], 'action' => $page['Page']['action'], 'params' => $page['Page']['params']);
         if (!empty($page['Page']['params'])) {
             foreach ($page['Page']['params'] as $k => $v) {
                 $params[$k] = $v;
             }
         }
         return $params;
     }
     return array();
 }
Example #24
0
 function route()
 {
     //Event::trigger('on_before_route');
     if ($this->site != 'admin') {
         $params = array();
         Route::translate($params);
     } else {
         $params = array('extension' => Request::data('ext', ''), 'controller' => Request::data('cont', ''), 'action' => Request::data('act', ''));
         if (empty($params['extension']) and empty($params['controller'])) {
             $params['controller'] = 'cpanel';
         }
     }
     $this->extension = !empty($params['extension']) ? $params['extension'] : '';
     $this->controller = !empty($params['controller']) ? $params['controller'] : '';
     $this->action = !empty($params['action']) ? $params['action'] : '';
     //set the active route data in the request
     Request::set('_Route.ext', $this->extension);
     Request::set('_Route.cont', $this->controller);
     Request::set('_Route.act', $this->action);
     foreach ($params as $k => $var) {
         if (strlen(Request::data($k)) == 0 and !in_array($k, array('extension', 'controller', 'action', 'params'))) {
             Request::set($k, $var);
             Request::set('_Route.' . $k, $var);
         }
     }
     if (!empty($params['params'])) {
         $this->set($params['params']);
         Request::set('_Route.params', $params['params']);
     }
     //Event::trigger('on_after_route', $params);
 }
Example #25
0
require_once 'app/controllers/studip_controller.php';
// Local includes
$error_reporting = error_reporting();
require 'vendor/Slim/Slim/Slim.php';
error_reporting($error_reporting);
require_once 'classes/Router.php';
require_once 'classes/Helper.php';
require_once 'classes/OAuth.php';
require_once 'classes/HTTPAuth.php';
require_once 'app/models/OAuthUser.php';
require_once 'app/models/OAuthConsumer.php';
require_once 'app/models/Permissions.php';
// Populate $_DELETE, $_HEAD, $_OPTIONS and $_PUT
foreach (words('DELETE HEAD OPTIONS PUT') as $method) {
    $var = '_' . $method;
    $GLOBALS[$var] = array();
    if ($_SERVER['REQUEST_METHOD'] == $method) {
        parse_str(file_get_contents('php://input'), $GLOBALS[$var]);
        foreach ($GLOBALS[$var] as $key => $value) {
            Request::set($key, $value);
        }
        $_REQUEST = array_merge($_REQUEST, $GLOBALS[$var]);
    }
}
// Autoload
spl_autoload_register(function ($name) {
    @(include 'vendor/oauth-php/library/' . $name . '.php');
}, false, true);
// Set up OAuth database conncetion
$options = array('dsn' => 'mysql:host=' . $GLOBALS['DB_STUDIP_HOST'] . ';dbname=' . $GLOBALS['DB_STUDIP_DATABASE'], 'username' => $GLOBALS['DB_STUDIP_USER'], 'password' => $GLOBALS['DB_STUDIP_PASSWORD']);
OAuthStore::instance('PDO', $options);
Example #26
0
            }

        }
}

// inc if we have requests left in the upper
if (Request::submitted('inc_request') || $auto_inc)
    if ($_SESSION['resources_data']["requests_working_pos"] < sizeof($_SESSION['resources_data']["requests_working_on"])-1) {
        $i = 1;
        if ($_SESSION['resources_data']["skip_closed_requests"])
            while ((!$_SESSION['resources_data']["requests_open"][$_SESSION['resources_data']["requests_working_on"][$_SESSION['resources_data']["requests_working_pos"] + $i]["request_id"]]) && ($_SESSION['resources_data']["requests_working_pos"] + $i < sizeof($_SESSION['resources_data']["requests_open"])-1))
                $i++;
        if ((sizeof($_SESSION['resources_data']["requests_open"]) >= 1) && (($_SESSION['resources_data']["requests_open"][$_SESSION['resources_data']["requests_working_on"][$_SESSION['resources_data']["requests_working_pos"] + $i]["request_id"]]) || (!$_SESSION['resources_data']["skip_closed_requests"]))){
            $_SESSION['resources_data']["requests_working_pos"] = $_SESSION['resources_data']["requests_working_pos"] + $i;
        } elseif ($auto_inc)
            Request::set('dec_request', 1); //we cannot inc - so we are at the end and want to find an request below, so try do dec.
    }

// dec if we have requests left in the lower
if ((Request::submitted('dec_request')) || ($auto_dec))
    if ($_SESSION['resources_data']["requests_working_pos"] > 0) {
        $d = -1;
        if ($_SESSION['resources_data']["skip_closed_requests"])
            while ((!$_SESSION['resources_data']["requests_open"][$_SESSION['resources_data']["requests_working_on"][$_SESSION['resources_data']["requests_working_pos"] + $d]["request_id"]]) && ($_SESSION['resources_data']["requests_working_pos"] + $d > 0))
                $d--;
        if ((sizeof($_SESSION['resources_data']["requests_open"]) >= 1) && (($_SESSION['resources_data']["requests_open"][$_SESSION['resources_data']["requests_working_on"][$_SESSION['resources_data']["requests_working_pos"] + $d]["request_id"]]) || (!$_SESSION['resources_data']["skip_closed_requests"]))) {
            $_SESSION['resources_data']["requests_working_pos"] = $_SESSION['resources_data']["requests_working_pos"] + $d;
        }
    }

//inc/dec the limits of found rooms
Example #27
0
 /**
  * Autor / Tutor / Teacher action
  */
 public function index_action($order_by = null, $order = 'asc')
 {
     if ($GLOBALS['perm']->have_perm('root')) {
         throw new AccessDeniedException();
     }
     if ($GLOBALS['perm']->have_perm('admin')) {
         $this->redirect('my_courses/admin');
         return;
     }
     Navigation::activateItem('/browse/my_courses/list');
     PageLayout::setHelpKeyword("Basis.MeineVeranstaltungen");
     PageLayout::setTitle(_("Meine Veranstaltungen"));
     $config_sem = $GLOBALS['user']->cfg->MY_COURSES_SELECTED_CYCLE;
     if (!Config::get()->MY_COURSES_ENABLE_ALL_SEMESTERS && $config_sem == 'all') {
         $config_sem = 'future';
     }
     $this->_my_sem_open = $GLOBALS['user']->cfg->MY_COURSES_OPEN_GROUPS;
     $group_field = $GLOBALS['user']->cfg->MY_COURSES_GROUPING;
     $deputies_enabled = Config::get()->DEPUTIES_ENABLE;
     $default_deputies_enabled = Config::get()->DEPUTIES_DEFAULTENTRY_ENABLE;
     $deputies_edit_about_enabled = Config::get()->DEPUTIES_EDIT_ABOUT_ENABLE;
     $studygroups_enabled = Config::get()->MY_COURSES_ENABLE_STUDYGROUPS;
     $this->config_sem_number = Config::get()->IMPORTANT_SEMNUMBER;
     $sem_create_perm = in_array(Config::get()->SEM_CREATE_PERM, array('root', 'admin', 'dozent')) ? Config::get()->SEM_CREATE_PERM : 'dozent';
     $this->sem_data = SemesterData::GetSemesterArray();
     $sem = $config_sem && $config_sem != '0' ? $config_sem : Config::get()->MY_COURSES_DEFAULT_CYCLE;
     if (Request::option('sem_select')) {
         $sem = Request::get('sem_select', $sem);
     }
     if (!in_array($sem, words('future all last current')) && isset($sem)) {
         Request::set('sem_select', $sem);
     }
     $forced_grouping = in_array(Config::get()->MY_COURSES_FORCE_GROUPING, getValidGroupingFields()) ? Config::get()->MY_COURSES_FORCE_GROUPING : 'sem_number';
     if ($forced_grouping == 'not_grouped') {
         $forced_grouping = 'sem_number';
     }
     if (!$group_field) {
         $group_field = 'sem_number';
     }
     if ($group_field == 'sem_number' && $forced_grouping != 'sem_number') {
         $group_field = $forced_grouping;
     }
     $this->group_field = $group_field === 'not_grouped' ? 'sem_number' : $group_field;
     // Needed parameters for selecting courses
     $params = array('group_field' => $this->group_field, 'order_by' => $order_by, 'order' => $order, 'studygroups_enabled' => $studygroups_enabled, 'deputies_enabled' => $deputies_enabled);
     // Save the semester in session
     $this->sem_courses = MyRealmModel::getPreparedCourses($sem, $params);
     $this->waiting_list = MyRealmModel::getWaitingList($GLOBALS['user']->id);
     $this->sem = $sem;
     $this->order = $order;
     $this->order_by = $order_by;
     $this->default_deputies_enabled = $default_deputies_enabled;
     $this->deputies_edit_about_enabled = $deputies_edit_about_enabled;
     $this->my_bosses = $default_deputies_enabled ? getDeputyBosses($GLOBALS['user']->id) : array();
     // Check for new contents
     $new_contents = $this->check_for_new($this->sem_courses, $this->group_field);
     $this->nav_elements = MyRealmModel::calc_nav_elements($this->sem_courses, $this->group_field);
     //
     if ($tabularasa = $this->flash['tabularasa']) {
         $details = array();
         if ($new_contents) {
             $details[] = sprintf(_('Seit Ihrem letzten Seitenaufruf (%s) sind allerdings neue Inhalte hinzugekommen.'), reltime($tabularasa));
         }
         $message_box = MessageBox::success(_('Alles als gelesen markiert!'), $details);
         PageLayout::postMessage($message_box);
     }
     // create settings url depended on selected cycle
     if (isset($sem) && !in_array($sem, words('future all last current'))) {
         $this->settings_url = sprintf('dispatch.php/my_courses/groups/%s', $sem);
     } else {
         $this->settings_url = 'dispatch.php/my_courses/groups';
     }
     $sidebar = Sidebar::get();
     $sidebar->setImage('sidebar/seminar-sidebar.png');
     $this->setSemesterWidget($sem);
     $setting_widget = new ActionsWidget();
     if ($new_contents) {
         $setting_widget->addLink(_('Alles als gelesen markieren'), $this->url_for('my_courses/tabularasa/' . $sem . '/', time()), Icon::create('accept', 'clickable'));
     }
     $setting_widget->addLink(_('Farbgruppierung ändern'), URLHelper::getLink($this->settings_url), Icon::create('group4', 'clickable'), array('data-dialog' => ''));
     if (Config::get()->MAIL_NOTIFICATION_ENABLE) {
         $setting_widget->addLink(_('Benachrichtigungen anpassen'), URLHelper::getLink('dispatch.php/settings/notification'), Icon::create('mail', 'clickable'));
     }
     if ($sem_create_perm == 'dozent' && $GLOBALS['perm']->have_perm('dozent')) {
         $setting_widget->addLink(_('Neue Veranstaltung anlegen'), URLHelper::getLink('dispatch.php/course/wizard'), Icon::create('seminar+add', 'clickable'));
     }
     $setting_widget->addLink(_('Veranstaltung hinzufügen'), URLHelper::getLink('dispatch.php/search/courses'), Icon::create('seminar', 'clickable'));
     $sidebar->addWidget($setting_widget);
     $this->setGroupingSelector($this->group_field);
 }
Example #28
0
 public function importInstance($record, CsvImportProfile $profile)
 {
     $this->className = 'Product';
     $impReq = new Request();
     $defLang = $this->application->getDefaultLanguageCode();
     $references = array('DefaultImage' => 'ProductImage', 'Manufacturer', 'ShippingClass', 'TaxClass');
     $cat = $this->getCategory($profile, $record);
     $extraCategories = null;
     $fields = $profile->getSortedFields();
     if (isset($fields['Categories']['ExtraCategories'])) {
         $extraCategories = explode('; ', $record[$fields['Categories']['ExtraCategories']]);
     }
     if (isset($fields['Product']) && $cat) {
         $product = null;
         if (isset($fields['Product']['ID']) && !empty($record[$fields['Product']['ID']])) {
             $id = $record[$fields['Product']['ID']];
             if (ActiveRecord::objectExists('Product', $id)) {
                 $product = Product::getInstanceByID($id, Product::LOAD_DATA, $references);
             }
         } else {
             if (isset($fields['Product']['sku']) && !empty($record[$fields['Product']['sku']])) {
                 $product = Product::getInstanceBySku($record[$fields['Product']['sku']], $references);
             }
         }
         if ($product && $product->getID()) {
             $this->registerImportedID($product->getID());
         }
         if (!$product && 'update' == $this->options['action'] || $product && 'add' == $this->options['action']) {
             return false;
         }
         if ($product) {
             $product->loadSpecification();
             $product->loadPricing();
         } else {
             if ($cat instanceof Category) {
                 $product = Product::getNewInstance($cat);
             } else {
                 $product = $cat->createChildProduct();
             }
             $product->isEnabled->set(true);
         }
         // product information
         $impReq->clearData();
         foreach ($profile->getFields() as $csvIndex => $field) {
             $column = $field['name'];
             $params = $field['params'];
             if (!isset($record[$csvIndex]) || empty($column)) {
                 continue;
             }
             $value = $record[$csvIndex];
             list($className, $field) = explode('.', $column, 2);
             if (isset($params['language'])) {
                 $lang = $params['language'];
                 if ($lang != $defLang) {
                     $field .= '_' . $lang;
                 }
             }
             if ($value) {
                 if ('Product.parentID' == $column) {
                     $product->parent->set();
                     continue;
                 }
                 if ('Product.parentSKU' == $column) {
                     $product->parent->set(Product::getInstanceBySKU($value));
                     continue;
                 }
             }
             if ('Product.taxClass' == $column) {
                 $product->taxClass->set(TaxClass::findByName($value));
             }
             if ('Product.shippingClass' == $column) {
                 $product->shippingClass->set(ShippingClass::findByName($value));
             }
             if ('Product' == $className) {
                 if ('shippingWeight' == $field) {
                     if ($this->application->getConfig()->get('UNIT_SYSTEM') == 'ENGLISH') {
                         $value = $value / 0.45359237;
                     }
                 }
                 if ('shippingWeight' == $field && $product->parent->get()) {
                     $value = $this->setChildSetting($product, 'weight', $value);
                 }
                 $impReq->set($field, $value);
             } else {
                 if ('Manufacturer' == $className) {
                     $impReq->set('manufacturer', $value);
                 } else {
                     if ('ProductPrice.price' == $column) {
                         if ($product->parent->get()) {
                             $value = $this->setChildSetting($product, 'price', $value);
                         }
                         $value = preg_replace('/,([0-9]{3})/', '\\1', $value);
                         $value = (double) preg_replace('/[^\\.0-9]/', '', str_replace(',', '.', $value));
                         $currency = isset($params['currency']) ? $params['currency'] : $this->application->getDefaultCurrencyCode();
                         $quantityLevel = isset($params['quantityLevel']) ? $params['quantityLevel'] : '';
                         $group = isset($params['group']) ? $params['group'] : '';
                         $price = $product->getPricingHandler()->getPriceByCurrencyCode($currency);
                         $product->getPricingHandler()->setPrice($price);
                         if ($group || $quantityLevel) {
                             if ($value > 0) {
                                 $quantity = $quantityLevel ? $record[$fields['ProductPrice'][$quantityLevel]] : 1;
                                 $group = $group ? UserGroup::getInstanceByID($group) : null;
                                 $price->setPriceRule($quantity, $group, $value);
                             }
                         } else {
                             $price->price->set($value);
                         }
                     } else {
                         if ('ProductPrice.listPrice' == $column) {
                             $value = (double) preg_replace('/[^\\.0-9]/', '', str_replace(',', '.', $value));
                             $currency = $params['currency'];
                             $price = $product->getPricingHandler()->getPriceByCurrencyCode($currency);
                             $price->listPrice->set($value);
                             $product->getPricingHandler()->setPrice($price);
                         } else {
                             if ('ProductVariation' == $className) {
                                 if ($parent = $product->parent->get()) {
                                     $this->importProductVariationValue($product, $field, $value);
                                 } else {
                                     $this->importVariationType($product, $field, $value);
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $product->loadRequestData($impReq);
         $product->save();
         $this->importAttributes($product, $record, $fields, 'specField');
         $this->setLastImportedRecordName($product->getValueByLang('name'));
         if (isset($fields['ProductImage']['mainurl'])) {
             if (!($image = $product->defaultImage->get())) {
                 $image = ProductImage::getNewInstance($product);
             }
             $image->setOwner($product);
             // this is needed when ProductApi imports default ProductImage.
             $this->importImage($image, $record[$fields['ProductImage']['mainurl']]);
             unset($image);
         }
         if (isset($fields['ProductAdditionalImage'])) {
             foreach ($fields['ProductAdditionalImage'] as $index) {
                 $this->importImage(ProductImage::getNewInstance($product), $record[$index]);
             }
         }
         if (isset($fields['ProductImage']['Images'])) {
             $images = explode('; ', $record[$fields['ProductImage']['Images']]);
             if ($images) {
                 $product->deleteRelatedRecordSet('ProductImage');
                 foreach ($images as $path) {
                     $image = ProductImage::getNewInstance($product);
                     $this->importImage($image, $path);
                     unset($image);
                 }
             }
         }
         if (isset($fields['ProductOption']['options'])) {
             $options = explode('; ', $record[$fields['ProductOption']['options']]);
             if ($options) {
                 $product->deleteRelatedRecordSet('ProductOption');
                 foreach ($options as $option) {
                     $parts = explode(':', $option, 2);
                     if (count($parts) < 2) {
                         continue;
                     }
                     $optionInstance = ProductOption::getNewInstance($product);
                     $optionInstance->setValueByLang('name', null, trim($parts[0]));
                     $optionInstance->type->set(ProductOption::TYPE_SELECT);
                     $optionInstance->isDisplayed->set(true);
                     $optionInstance->save();
                     foreach (explode(',', $parts[1]) as $choice) {
                         $choiceInstance = ProductOptionChoice::getNewInstance($optionInstance);
                         $choiceInstance->setValueByLang('name', null, trim($choice));
                         $choiceInstance->save();
                     }
                 }
             }
         }
         // create variation by name
         if ((isset($fields['Product']['parentID']) || isset($fields['Parent']['parentSKU'])) && !isset($fields['ProductVariation']) && $product->parent->get()) {
             $this->importProductVariationValue($product, 1, $product->getValueByLang('name', 'en'));
         }
         // additional categories
         if (is_array($extraCategories)) {
             $this->importAdditionalCategories($profile, $product, $extraCategories);
         }
         if ($this->callback) {
             call_user_func($this->callback, $product);
         }
         $product->__destruct();
         $product->destruct(true);
         ActiveRecord::clearPool();
         return true;
     }
 }
Example #29
0
 static function route(Request $request)
 {
     $url = explode('?', $request->getServer('REQUEST_URI'));
     $path = $url[0];
     while (substr($path, -1) == '/') {
         $path = mb_substr($path, 0, mb_strlen($path) - 1);
     }
     $path_components = explode('/', $path);
     $pathMethodArray = explode('.', $path_components[count($path_components) - 1]);
     if (count($pathMethodArray) == 2) {
         $path_components[count($path_components) - 1] = $pathMethodArray[0];
         $path_components[] = $pathMethodArray[1];
     }
     //Loop through all the routes we defined in route.php, and try to find one that matches our request
     foreach ($GLOBALS['routes'] as $route => $controllerString) {
         $route_components = explode("/", $route);
         $routeMethodArray = explode('.', $route_components[count($route_components) - 1]);
         if (count($routeMethodArray) == 2) {
             $route_components[count($route_components) - 1] = $routeMethodArray[0];
             $route_components[] = $routeMethodArray[1];
         }
         $action = "index";
         $module = '';
         $i = 0;
         $objects = array();
         $goodRoute = true;
         $forceRoute = false;
         $path_components = array_pad($path_components, count($route_components), '');
         $parameters = array();
         //Handle routes that call a specific action
         $controller_action_array = explode(":", $controllerString);
         if (count($controller_action_array) == 2) {
             $controller = $controller_action_array[0];
             $action = $controller_action_array[1];
         } elseif (count($controller_action_array) == 3) {
             $module = $controller_action_array[0];
             $controller = $controller_action_array[1];
             $action = $controller_action_array[2];
         } elseif (count($controller_action_array) == 1) {
             $controller = $controller_action_array[0];
         }
         //Loop through each component of this route until we find a part that doesn't match, or we run out of url
         foreach ($route_components as $route_component) {
             //This part of the route is a named parameter
             if (substr($route_component, 0, 1) == ":") {
                 $parameters[substr($route_component, 1)] = $path_components[$i];
                 //This part of the route is an action for a controller
             } elseif ($route_component == "[action]") {
                 if ($path_components[$i] != "") {
                     $action = str_replace("-", "_", $path_components[$i]);
                 }
             } elseif ($route_component == "[controller]") {
                 if ($path_components[$i] != "") {
                     $controller = str_replace("-", "_", $path_components[$i]);
                 }
             } elseif ($route_component == "*") {
                 echo "Bad match: " . str_replace("-", "_", $route_component) . " != " . $path_components[$i] . "<br />";
                 $forceRoute = true;
             } elseif ($route_component != $path_components[$i] && str_replace("-", "_", $route_component) != $path_components[$i]) {
                 echo "Bad match: " . str_replace("-", "_", $route_component) . " != " . $path_components[$i] . "<br />";
                 $goodRoute = false;
                 break;
             }
             $i++;
         }
         //This route is a match for our request, let's get the controller working on it
         if ($forceRoute || $goodRoute && ($i >= count($path_components) || $path_components[$i] == "")) {
             $request->set('module', $module);
             $request->set('controller', $controller);
             $request->set('action', $action);
             foreach ($parameters as $key => $value) {
                 $request->set($key, $value);
             }
             return $request;
         }
     }
     return $request;
 }
Example #30
0
 /**
  * displays a paginated member overview of a studygroup
  *
  * @param string id of a studypgroup
  * @param string page number the current page
  *
  * @return void
  *
  */
 function members_action()
 {
     $id = $_SESSION['SessionSeminar'];
     PageLayout::setTitle(getHeaderLine($_SESSION['SessionSeminar']) . ' - ' . _("Teilnehmende"));
     Navigation::activateItem('/course/members');
     PageLayout::setHelpKeyword('Basis.StudiengruppenBenutzer');
     Request::set('choose_member_parameter', $this->flash['choose_member_parameter']);
     object_set_visit_module('participants');
     $this->last_visitdate = object_get_visit($id, 'participants');
     $sem = Course::find($id);
     $this->anzahl = StudygroupModel::countMembers($id);
     $this->groupname = $sem->getFullname();
     $this->sem_id = $id;
     $this->groupdescription = $sem->beschreibung;
     $this->moderators = $sem->getMembersWithStatus('dozent');
     $this->tutors = $sem->getMembersWithStatus('tutor');
     $this->autors = $sem->getMembersWithStatus('autor');
     $this->accepted = $sem->admission_applicants->findBy('status', 'accepted');
     $this->sem_class = Course::findCurrent()->getSemClass();
     $inviting_search = new SQLSearch("SELECT auth_user_md5.user_id, {$GLOBALS['_fullname_sql']['full_rev']} as fullname, username, perms " . "FROM auth_user_md5 " . "LEFT JOIN user_info ON (auth_user_md5.user_id = user_info.user_id) " . "LEFT JOIN seminar_user ON (auth_user_md5.user_id = seminar_user.user_id AND seminar_user.Seminar_id = '" . addslashes($id) . "') " . "WHERE perms  NOT IN ('root', 'admin') " . "AND " . get_vis_query() . " AND (username LIKE :input OR Vorname LIKE :input " . "OR CONCAT(Vorname,' ',Nachname) LIKE :input " . "OR CONCAT(Nachname,' ',Vorname) LIKE :input " . "OR Nachname LIKE :input OR {$GLOBALS['_fullname_sql']['full_rev']} LIKE :input) " . "ORDER BY fullname ASC", _("Nutzer suchen"), "user_id");
     $this->rechte = $GLOBALS['perm']->have_studip_perm("tutor", $id);
     $actions = new ActionsWidget();
     if ($this->rechte) {
         $mp = MultiPersonSearch::get('studygroup_invite_' . $id)->setLinkText(_('Neue Gruppenmitglieder-/innen einladen'))->setLinkIconPath("")->setTitle(_('Neue Gruppenmitglieder/-innen einladen'))->setExecuteURL($this->url_for('course/studygroup/execute_invite/' . $id, array('view' => Request::get('view'))))->setSearchObject($inviting_search)->addQuickfilter(_('Adressbuch'), User::findCurrent()->contacts->pluck('user_id'))->setNavigationItem('/course/members')->render();
         $element = LinkElement::fromHTML($mp, Icon::create('community+add', 'clickable'));
         $actions->addElement($element);
     }
     if ($this->rechte || $sem->getSemClass()['studygroup_mode']) {
         $actions->addLink(_('Nachricht an alle Gruppenmitglieder verschicken'), $this->url_for('course/studygroup/message/' . $id), Icon::create('mail', 'clickable'), array('data-dialog' => 1));
     }
     if ($actions->hasElements()) {
         Sidebar::get()->addWidget($actions);
     }
     $this->invitedMembers = StudygroupModel::getInvitations($id);
 }