コード例 #1
0
 /**
  * Create HTML link element from data item
  *
  * @param  \stdClass $item
  * @return string
  */
 public function itemToString(\stdClass $item)
 {
     $attributes = (array) $item;
     if (isset($attributes['type']) && ($attributes['type'] == 'text/css' || $attributes['type'] == 'text/less')) {
         // This is a stylesheet, consider extension and compile .less to .css
         if ($attributes['type'] == 'text/less' || \MUtil_String::endsWith($attributes['href'], '.less', true)) {
             $this->compile($this->view, $attributes['href'], false);
             // Modify object, not the derived array
             $item->type = 'text/css';
             $item->href = substr($attributes['href'], 0, -4) . 'css';
         }
     }
     $version = $this->view->currentVersion;
     if (property_exists($item, 'href')) {
         $item->href = $item->href . '?' . $version;
     }
     return \Zend_View_Helper_HeadLink::itemToString($item);
 }
コード例 #2
0
 /**
  * Should handle execution of the task, taking as much (optional) parameters as needed
  *
  * The parameters should be optional and failing to provide them should be handled by
  * the task
  */
 public function execute($lineNr = null, $fieldId = null, $fieldSub = null, $fieldCalc = null)
 {
     $batch = $this->getBatch();
     $import = $batch->getVariable('import');
     if (!(isset($import['trackId']) && $import['trackId'] && $fieldId)) {
         // Do nothing
         return;
     }
     $tracker = $this->loader->getTracker();
     $trackEngine = $tracker->getTrackEngine($import['trackId']);
     $fieldCodes = $import['fieldCodes'];
     $fieldModel = $trackEngine->getFieldsMaintenanceModel(true, 'edit');
     $roundOrders = $import['roundOrders'];
     $saveData['gtf_id_field'] = $fieldId;
     $saveData['sub'] = $fieldSub;
     $saveData['gtf_id_track'] = $import['trackId'];
     $calcFields = is_array($fieldCalc) ? $fieldCalc : explode('|', trim($fieldCalc, '|'));
     if (!$calcFields) {
         return;
     }
     foreach ($calcFields as $field) {
         if (isset($fieldCodes[$field]) && $fieldCodes[$field]) {
             $saveData['gtf_calculate_using'][] = $fieldCodes[$field];
         } else {
             // Actually this code currently is PULSE specific
             if (\MUtil_String::startsWith($field, '{r')) {
                 $roundOrder = substr($field, 2, -1);
                 if (isset($roundOrders[$roundOrder]) && $roundOrders[$roundOrder]) {
                     $saveData['gtf_calculate_using'][] = $roundOrders[$roundOrder];
                 } else {
                     $saveData['gtf_calculate_using'][] = $field;
                 }
             }
         }
     }
     \MUtil_Echo::track($saveData, $fieldId);
     $fieldModel->save($saveData);
 }
コード例 #3
0
 /**
  * Should handle execution of the task, taking as much (optional) parameters as needed
  *
  * The parameters should be optional and failing to provide them should be handled by
  * the task
  *
  * @param string $location
  * @param string $sql
  * @param int $completed
  * @param int $patchId
  */
 public function execute($location = null, $sql = null, $completed = null, $patchId = null)
 {
     $batch = $this->getBatch();
     $db = $this->patcher->getPatchDatabase($location);
     $data['gpa_executed'] = 1;
     $data['gpa_changed'] = new \MUtil_Db_Expr_CurrentTimestamp();
     try {
         $stmt = $db->query($sql);
         if ($rows = $stmt->rowCount()) {
             // No translation to avoid conflicting translations
             $data['gpa_result'] = 'OK: ' . $rows . ' changed';
         } else {
             $data['gpa_result'] = 'OK';
         }
         $data['gpa_completed'] = 1;
     } catch (\Zend_Db_Statement_Exception $e) {
         $message = $e->getMessage();
         // Make sure these do not remain uncompleted
         if (\MUtil_String::contains($message, 'Duplicate column name')) {
             $data['gpa_result'] = 'Column exists in table';
             $data['gpa_completed'] = 1;
         } elseif (\MUtil_String::contains($message, "DROP") && \MUtil_String::contains($message, 'check that column/key exists')) {
             $data['gpa_result'] = 'Column does not exists in table';
             $data['gpa_completed'] = 1;
         } else {
             $data['gpa_result'] = substr($message, 0, 254);
             $data['gpa_completed'] = $completed ? $completed : 0;
         }
         $batch->addMessage($data['gpa_result']);
     }
     // $this->db, not the database the patch was executed on
     $this->db->update('gems__patches', $data, $this->db->quoteInto('gpa_id_patch = ?', $patchId));
     // \MUtil_Echo::track($data, $patchId);
     $batch->addToCounter('executed');
     $batch->setMessage('executed', sprintf($this->_('%d patch(es) executed.'), $batch->getCounter('executed')));
 }
コード例 #4
0
ファイル: Cli.php プロジェクト: GemsTracker/MUtil
 /**
  * Processes a request and sets its controller and action.  If
  * no route was possible, an exception is thrown.
  *
  * @param  \Zend_Controller_Request_Abstract
  * @throws \Zend_Controller_Router_Exception
  * @return \Zend_Controller_Request_Abstract|boolean
  */
 public function route(\Zend_Controller_Request_Abstract $request)
 {
     $options = array('help|h' => 'Show this help', 'org|o=i' => 'The user organization number', 'pwd|p=s' => 'User password', 'user|u=s' => 'The user name');
     $getopt = new \Zend_Console_Getopt($options);
     try {
         $getopt->parse();
     } catch (\Zend_Console_Getopt_Exception $e) {
         echo $this->_expandMessage($e);
         exit;
     }
     if ($getopt->getOption('h')) {
         // $getopt->s
         echo $this->_expandMessage($getopt);
         exit;
     }
     if ($request instanceof \MUtil_Controller_Request_Cli) {
         $request->setUserLogin($getopt->getOption('u'), $getopt->getOption('o'), $getopt->getOption('p'));
     }
     $arguments = $getopt->getRemainingArgs();
     if ($arguments) {
         $controller = array_shift($arguments);
         $action = array_shift($arguments);
         if (!$action) {
             $action = 'index';
         }
         if (preg_match('/^\\w+(-\\w+)*$/', $controller) && preg_match('/^\\w+(-\\w+)*$/', $action)) {
             $request->setControllerName($controller);
             $request->setActionName($action);
             $params[$request->getControllerKey()] = $controller;
             $params[$request->getActionKey()] = $action;
             foreach ($arguments as $arg) {
                 if (\MUtil_String::contains($arg, '=')) {
                     list($name, $value) = explode('=', $arg, 2);
                 } else {
                     $name = $arg;
                     $value = '';
                 }
                 $params[$name] = $value;
             }
             $request->setParams($params);
             return $request;
         }
         echo "Invalid command: {$controller}/{$action}.\n", exit;
     }
     echo "No command given.\n\n";
     echo $this->_expandMessage($getopt), exit;
 }
コード例 #5
0
 /**
  * Remove password and pwd contents and clean up message status data and single item arrays
  *
  * @param array $data
  * @return mixed
  */
 private function _toCleanArray(array $data)
 {
     switch (count($data)) {
         case 0:
             return null;
         case 1:
             if (isset($data[0])) {
                 // Return array content when only one item
                 // with the key 0.
                 if (is_array($data[0])) {
                     return $this->_toCleanArray($data[0]);
                 } else {
                     return $data[0];
                 }
             }
             break;
         case 2:
             if (isset($data[0], $data[1]) && is_string($data[1])) {
                 if ('info' === $data[1] || 'warning' === $data[1] || 'error' === $data[1]) {
                     if (is_array($data[0])) {
                         return $this->_toCleanArray($data[0]);
                     } else {
                         return $data[0];
                     }
                 }
             }
     }
     $output = array();
     foreach ($data as $key => $value) {
         if (is_array($value)) {
             $output[$key] = $this->_toCleanArray($value);
         } else {
             if (is_string($value)) {
                 if (\MUtil_String::contains($key, 'password', true) || \MUtil_String::contains($key, 'pwd', true)) {
                     $value = '****';
                 }
             }
             $output[$key] = $value;
         }
     }
     return $output;
 }
コード例 #6
0
ファイル: StringTest.php プロジェクト: GemsTracker/MUtil
 /**
  * Remove nothing as both strings have no common starting characters
  */
 public function testStripStringLeftNothing()
 {
     $result = MUtil_String::stripStringLeft('abcdef', 'xabc');
     $this->assertEquals($result, 'abcdef');
 }
コード例 #7
0
 /**
  * Returns an array of items for a page.
  *
  * @param  integer $offset Page offset
  * @param  integer $itemCountPerPage Number of items per page
  * @return array
  */
 public function getItems($offset, $itemCountPerPage)
 {
     // Cast to integers, as $itemCountPerPage can be string sometimes and that would fail later checks
     $offset = (int) $offset;
     $itemCountPerPage = (int) $itemCountPerPage;
     if ($this->_lastOffset === $offset && $this->_lastItemCount === $itemCountPerPage && null !== $this->_lastItems) {
         return $this->_lastItems;
     }
     $this->_lastOffset = $offset;
     $this->_lastItemCount = $itemCountPerPage;
     // Optimization: by using the MySQL feature SQL_CALC_FOUND_ROWS
     // we can get the count and the results in a single query.
     $db = $this->_select->getAdapter();
     if (null === $this->_count && $db instanceof \Zend_Db_Adapter_Mysqli) {
         $this->_select->limit($itemCountPerPage, $offset);
         $sql = $this->_select->__toString();
         if (\MUtil_String::startsWith($sql, 'select ', true)) {
             $sql = 'SELECT SQL_CALC_FOUND_ROWS ' . substr($sql, 7);
         }
         $this->_lastItems = $db->fetchAll($sql);
         $this->_count = $db->fetchOne('SELECT FOUND_ROWS()');
     } else {
         $this->_lastItems = $this->_selectAdapter->getItems($offset, $itemCountPerPage);
     }
     if (is_array($this->_lastItems)) {
         if (isset($this->_model->prefetchIterator) && $this->_model->prefetchIterator) {
             $this->_lastItems = new \ArrayIterator($this->_lastItems);
         }
         $this->_lastItems = $this->_model->processAfterLoad($this->_lastItems, false, false);
     }
     return $this->_lastItems;
 }
コード例 #8
0
 /**
  * Creates a filter for this model for the given wildcard search text.
  *
  * @param string $searchText
  * @return array An array of filter statements for wildcard text searching for this model type
  */
 public function getTextSearchFilter($searchText)
 {
     $filter = array();
     if ($searchText) {
         $fields = array();
         foreach ($this->getItemNames() as $name) {
             // TODO: multiOptions integratie
             if ($this->get($name, 'label')) {
                 $fields[] = $name;
             }
         }
         if ($fields) {
             foreach ($this->getTextSearches($searchText) as $searchOn) {
                 $textFilter = array();
                 // Almost always use, this allows reuse
                 $textFunction = function ($value) use($searchOn) {
                     // \MUtil_Echo::track($value . ' - ' . $searchOn . ' = ' . \MUtil_String::contains($value, $searchOn));
                     return \MUtil_String::contains($value, $searchOn, true);
                 };
                 foreach ($fields as $name) {
                     if ($options = $this->get($name, 'multiOptions')) {
                         $items = array();
                         foreach ($options as $value => $label) {
                             if (\MUtil_String::contains($label, $searchOn)) {
                                 $items[$value] = $value;
                             }
                         }
                         if ($items) {
                             if (count($items) == count($options)) {
                                 // This filter always returns true, do not add this filter
                                 // \MUtil_Echo::track('Always true');
                                 $textFilter = false;
                                 break;
                             }
                             // Function is different for each multiOptions
                             $textFilter[$name] = function ($value) use($items) {
                                 return array_key_exists($value, $items);
                             };
                         }
                     } else {
                         $textFilter[$name] = $textFunction;
                     }
                 }
                 if ($textFilter) {
                     $filter[] = $textFilter;
                 }
             }
         }
     }
     return $filter;
 }
コード例 #9
0
 /**
  * Get the structural patches for the given patch level
  * @param int $patchLevel
  * @return array
  */
 public function getStructuralPatches($patchLevel)
 {
     $patches = $this->db->fetchAll("SELECT * FROM gems__patches WHERE gpa_level = ? ORDER BY gpa_location, gpa_name, gpa_order", $patchLevel);
     foreach ($patches as $patchId => $patch) {
         if (\MUtil_String::startsWith(trim($patch['gpa_sql']), 'INSERT', true) || \MUtil_String::startsWith(trim($patch['gpa_sql']), 'UPDATE', true) || \MUtil_String::startsWith(trim($patch['gpa_sql']), 'DELETE', true)) {
             unset($patches[$patchId]);
         }
     }
     return $patches;
 }
コード例 #10
0
 /**
  * Get the cacheId for the organization
  *
  * @return string
  */
 private function _getCacheId()
 {
     return \MUtil_String::toCacheId(GEMS_PROJECT_NAME . '__' . get_class($this) . '__' . $this->_id);
 }
コード例 #11
0
 /**
  * FilesystemIterator::current — The current file
  *
  * @return mixed null or artray
  */
 public function current()
 {
     $file = parent::current();
     if (!$file instanceof SplFileInfo) {
         return null;
     }
     $real = \MUtil_File::cleanupSlashes($file->getRealPath());
     // The relative file name uses the windows directory seperator convention as this
     // does not screw up the use of this value as a parameter
     $rel = \MUtil_File::cleanupSlashes(\MUtil_String::stripStringLeft($real, $this->startPath));
     // Function was first implemented in PHP 5.3.6
     if (method_exists($file, 'getExtension')) {
         $extension = $file->getExtension();
     } else {
         $extension = pathinfo($file->getFilename(), PATHINFO_EXTENSION);
     }
     return array('fullpath' => $real, 'relpath' => $rel, 'urlpath' => str_replace(array('\\', '/'), '|', $rel), 'path' => \MUtil_File::cleanupSlashes($file->getPath()), 'filename' => $file->getFilename(), 'extension' => $extension, 'content' => \MUtil_Lazy::call('file_get_contents', $real), 'size' => $file->getSize(), 'changed' => new \MUtil_Date($file->getMTime()));
 }
コード例 #12
0
 /**
  * Converting the field value when saving to a respondent track
  *
  * @param array $currentValue The current value
  * @param array $fieldData The other values loaded so far
  * @return mixed the new value
  */
 public function onFieldDataSave($currentValue, array $fieldData)
 {
     if (null === $currentValue || $currentValue instanceof \Zend_Db_Expr || \MUtil_String::startsWith($currentValue, 'current_', true)) {
         return $currentValue;
     }
     $saveFormat = $this->getStorageFormat();
     if ($currentValue instanceof \Zend_Date) {
         return $currentValue->toString($saveFormat);
     } else {
         $displayFormat = $this->getDateFormat();
         $saveDate = \MUtil_Date::ifDate($currentValue, array($displayFormat, $saveFormat, \Gems_Tracker::DB_DATETIME_FORMAT));
         if ($saveDate instanceof \Zend_Date) {
             return $saveDate->toString($saveFormat);
         }
     }
     return (string) $currentValue;
 }
コード例 #13
0
 /**
  * Hook 6: Called after \Zend_Controller_Router has determined the route set by the request.
  *
  * This events enables you to adjust the route after the routing has run it's course.
  *
  * Not initialized is the $controller object.
  *
  * Previous hook: routeStartup()
  * Actions since: $router->route()
  * Actions after: nothing, but the route consisting of controller, action and module should now be fixed
  * Next hook: dispatchLoopStartup()
  *
  * Also sets $this->currentOrganization and $this->menu to access afterwards
  *
  * @param  \Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function routeShutdown(\Zend_Controller_Request_Abstract $request)
 {
     $loader = $this->getLoader();
     // Load the menu. As building the menu can depend on all resources and the request, we do it here.
     //
     // PS: The REQUEST is needed because otherwise the locale for translate is not certain.
     $menu = $loader->createMenu($this);
     $source = $menu->getParameterSource();
     $user = $this->_container->currentUser;
     $user->setRequest($request);
     $organization = $user->getCurrentOrganization();
     $organization->applyToMenuSource($source);
     $this->_container->currentOrganization = $organization;
     $this->_container->menu = $menu;
     $this->_updateVariable(array('currentOrganization', 'menu'));
     // Now is a good time to check for required values
     // Moved down here to prevent unit test from failing on missing salt
     $this->project->checkRequiredValues();
     /**
      * Check if we are in maintenance mode or not. This is triggeren by a file in the var/settings
      * directory with the name lock.txt
      */
     if ($this->getUtil()->getMaintenanceLock()->isLocked()) {
         if ($user->isActive() && !$user->hasPrivilege('pr.maintenance.maintenance-mode')) {
             //Still allow logoff so we can relogin as master
             if (!('index' == $request->getControllerName() && 'logoff' == $request->getActionName())) {
                 $this->setError($this->_('Please check back later.'), 401, $this->_('System is in maintenance mode'));
             }
             $user->unsetAsCurrentUser();
         } else {
             $this->addMessage($this->_('System is in maintenance mode'));
             \MUtil_Echo::r($this->_('System is in maintenance mode'));
         }
     }
     // Gems does not use index/index
     $action = $request->getActionName();
     if ('index' == $request->getControllerName() && ('index' == $action || $user->isActive() && 'login' == $action)) {
         // Instead Gems routes to the first available menu item when this is the request target
         if (!$user->gotoStartPage($menu, $request)) {
             $this->setError($this->_('No access to site.'), 401, $this->_('You have no access to this site.'), true);
             return;
         }
     } else {
         //find first allowed item in the menu
         $menuItem = $menu->find(array('action' => $request->getActionName(), 'controller' => $request->getControllerName()));
         // Display error when not having the right priviliges
         if (!($menuItem && $menuItem->get('allowed'))) {
             // When logged in
             if ($user->getUserId()) {
                 $this->setError($this->_('No access to page'), 403, sprintf($this->_('Access to the %s/%s page is not allowed for current role: %s.'), $request->getControllerName(), $request->getActionName(), $user->getRole()), true);
             } else {
                 // No longer logged in
                 if (\MUtil_Console::isConsole()) {
                     $this->setError('No access to page.', 401, sprintf('Controller "%s" action "%s" is not accessible.', $request->getControllerName(), $request->getActionName()), true);
                     return;
                 }
                 if ($request->getActionName() == 'autofilter') {
                     // Throw an exception + HTTP 401 when an autofilter is called
                     throw new \Gems_Exception("Session expired", 401);
                 }
                 $menuItem = $menu->findFirst(array('allowed' => true, 'visible' => true));
                 if ($menuItem) {
                     // Do not store previous request & show message when the intended action is logoff
                     if (!($request->getControllerName() == 'index' && $request->getActionName() == 'logoff')) {
                         $this->addMessage($this->_('You are no longer logged in.'));
                         $this->addMessage($this->_('You must login to access this page.'));
                         if (!\MUtil_String::contains($request->getControllerName() . $request->getActionName(), '.')) {
                             // save original request, we will redirect back once the user succesfully logs in
                             $staticSession = $this->getStaticSession();
                             $staticSession->previousRequestParameters = $request->getParams();
                             $staticSession->previousRequestMode = $request->isPost() ? "POST" : "GET";
                         }
                     }
                     $redirector = \Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
                     $redirector->gotoRoute($menuItem->toRouteUrl($request));
                 } else {
                     $this->setError($this->_('You are no longer logged in.'), 401, $this->_('You have no access to this site.'), true);
                     return;
                 }
             }
         }
     }
     if (isset($menuItem)) {
         $menuItem->applyHiddenParameters($request, $source);
         $menu->setCurrent($menuItem);
     }
 }
コード例 #14
0
 /**
  * A ModelAbstract->setOnSave() function that returns the input
  * date as a valid date.
  *
  * @see \MUtil_Model_ModelAbstract
  *
  * @param mixed $value The value being saved
  * @param boolean $isNew True when a new item is being saved
  * @param string $name The name of the current field
  * @param array $context Optional, the other values being saved
  * @return \Zend_Date
  */
 public function formatSaveDate($value, $isNew = false, $name = null, array $context = array())
 {
     if ($name && !(null === $value || $value instanceof \Zend_Db_Expr || \MUtil_String::startsWith($value, 'current_', true))) {
         $saveFormat = $this->getWithDefault($name, 'storageFormat', \Zend_Date::ISO_8601);
         if ($value instanceof \Zend_Date) {
             return $value->toString($saveFormat);
         } else {
             $displayFormat = $this->get($name, 'dateFormat');
             try {
                 return \MUtil_Date::format($value, $saveFormat, $displayFormat);
             } catch (\Zend_Exception $e) {
                 if (\Zend_Date::isDate($value, $saveFormat)) {
                     return $value;
                 }
                 throw $e;
             }
         }
     }
     return $value;
 }
コード例 #15
0
 /**
  * Check a filter for a match
  *
  * @param \Gems\Agenda\Gems_Agenda_Appointment $appointment
  * @return boolean
  */
 public function matchAppointment(\Gems_Agenda_Appointment $appointment)
 {
     return \MUtil_String::contains($appointment->getSubject(), $this->_data['gaf_filter_text1']);
 }
コード例 #16
0
ファイル: HeadLink.php プロジェクト: GemsTracker/MUtil
 /**
  * Create HTML link element from data item
  *
  * @param  \stdClass $item
  * @return string
  */
 public function itemToString(\stdClass $item)
 {
     $attributes = (array) $item;
     if (isset($attributes['type']) && ($attributes['type'] == 'text/css' || $attributes['type'] == 'text/less')) {
         // This is a stylesheet, consider extension and compile .less to .css
         if ($attributes['type'] == 'text/less' || \MUtil_String::endsWith($attributes['href'], '.less', true)) {
             $this->compile($this->view, $attributes['href'], false);
             // Modify object, not the derived array
             $item->type = 'text/css';
             $item->href = substr($attributes['href'], 0, -4) . 'css';
         }
     }
     return parent::itemToString($item);
 }
コード例 #17
0
 public function saveTemplate($template, $data)
 {
     $changed = 0;
     $config = $this->_loadConfig($this->_path);
     $original = $config->data->toArray();
     foreach ($original as $field => $value) {
         if ($value !== $data[$field]) {
             $config->data->{$field} = $data[$field];
             $changed = 1;
         }
     }
     if ($changed || true) {
         // Maybe shut off later, for now always recompile
         $writer = new \Zend_Config_Writer_Ini();
         unset($config->config);
         $writer->write($this->_path . '/template-local.ini', $config);
         // Also output to less file for variables
         $variables = $config->data->toArray();
         $file = fopen($this->_path . '/variables.less', 'w');
         fwrite($file, "/* GemsTracker variables, do not change directly, use template configuration screen */\n");
         foreach ($variables as $variable => $value) {
             fwrite($file, sprintf("@%s: %s;\n", $variable, $value));
         }
         fclose($file);
         // Force recompile of less files
         $compiled = 0;
         $view = \Zend_Layout::getMvcInstance()->getView();
         $headlink = $view->headLink();
         if ($headlink instanceof \MUtil_Less_View_Helper_HeadLink) {
             foreach ($data['sheets'] as $url) {
                 if (\MUtil_String::endsWith($url, '.less', true)) {
                     $result = $headlink->compile($view, $url, true);
                     if ($result) {
                         $compiled++;
                     }
                 }
             }
         }
         \Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger')->addMessage(sprintf($this->_('Compiled %s file(s)'), $compiled));
     }
     return $changed;
 }
コード例 #18
0
 /**
  * A specific report on a code file
  *
  * @param \SplFileInfo $filename
  * @return boolean
  */
 protected function addFileReport(\SplFileInfo $fileinfo)
 {
     // $extension = strtolower($fileinfo->getExtension());
     $extension = strtolower(pathinfo($fileinfo, PATHINFO_EXTENSION));
     if ('php' !== $extension && 'phtml' !== $extension) {
         return false;
     }
     $content = file_get_contents($fileinfo);
     $messages = array();
     if (preg_match('/Single.*Survey/', $fileinfo->getFilename())) {
         $messages[] = "This seems to be a file for (obsolete) SingleSurveys. This file can probably be removed.";
     }
     $this->_checkCodingChanged($fileinfo, $content, $messages);
     if (\MUtil_String::endsWith($fileinfo->getPath(), 'controllers')) {
         $this->_checkControllersChanged($fileinfo, $content, $messages);
     } else {
         $this->_checkSnippetsChanged($fileinfo, $content, $messages);
     }
     $this->_checkTablesChanged($fileinfo, $content, $messages);
     if (!$messages) {
         return false;
     }
     $this->html->h2(sprintf('Report on file %s', substr($fileinfo->getPathname(), strlen(GEMS_ROOT_DIR) + 1)));
     foreach ($messages as $message) {
         $this->html->pInfo($message);
     }
     return true;
 }
コード例 #19
0
ファイル: Log.php プロジェクト: GemsTracker/MUtil
 /**
  * Get the filename to use
  *
  * @param int $index
  * @return string
  */
 protected function _getLogFileName($index = null)
 {
     switch ($this->_logRotate) {
         case self::ROTATE_PER_MONTH:
             if (null === $index) {
                 $now = new \MUtil_Date();
                 $index = $now->toString(\Zend_Date::MONTH);
             } elseif ($index < 10) {
                 $index = "0" . $index;
             }
             $filename = $this->_logFileRoot . '-mon-' . $index . '.log';
             break;
         case self::ROTATE_PER_MONTH:
             if (null === $index) {
                 $now = new \MUtil_Date();
                 $index = $now->toString(\Zend_Date::WEEK);
             } elseif ($index < 10) {
                 $index = "0" . $index;
             }
             $filename = $this->_logFileRoot . '-wk-' . $index . '.log';
             break;
         default:
             $filename = $this->_logFileRoot;
             if (!\MUtil_String::endsWith($filename, '.log')) {
                 $filename .= '.log';
             }
             break;
     }
     return $filename;
 }
コード例 #20
0
 /**
  * Returns a select statement to find a corresponding user.
  *
  * @param string $login_name
  * @param int $organization
  * @return \Zend_Db_Select
  */
 protected function getUserClassSelect($login_name, $organization)
 {
     $select = $this->db->select();
     /**
      * tolerance field:
      * 1 - login and organization match
      * 2 - login found in an organization with access to the requested organization
      * 3 - login found in another organization without rights to the requested organiation
      *     (could be allowed due to privilege with rights to ALL organizations)
      */
     $select->from('gems__user_logins', array("gul_user_class", 'gul_id_organization', 'gul_login'))->where('gul_can_login = 1');
     if ($this->allowLoginOnWithoutOrganization && !$organization) {
         $select->columns(new \Zend_Db_Expr('1 AS tolerance'));
     } else {
         $select->from('gems__organizations', array())->columns(new \Zend_Db_Expr("CASE\n                            WHEN gor_id_organization = gul_id_organization THEN 1\n                            WHEN gor_accessible_by LIKE CONCAT('%:', gul_id_organization, ':%') THEN 2\n                            ELSE 3\n                        END AS tolerance"))->where('gor_active = 1')->where('gor_id_organization = ?', $organization)->order('tolerance');
     }
     $wheres[] = $this->db->quoteInto('gul_login = ?', $login_name);
     $isEmail = \MUtil_String::contains($login_name, '@');
     if ($isEmail && $this->allowStaffEmailLogin) {
         $rows = $this->db->fetchAll("SELECT gsf_login, gsf_id_organization FROM gems__staff WHERE gsf_email = ?", $login_name);
         if ($rows) {
             foreach ($rows as $row) {
                 $wheres[] = $this->db->quoteInto('gul_login = ? AND ', $row['gsf_login']) . $this->db->quoteInto('gul_id_organization = ?', $row['gsf_id_organization']);
             }
         }
     }
     if ($isEmail && $this->allowRespondentEmailLogin) {
         $rows = $this->db->fetchAll("SELECT gr2o_patient_nr, gr2o_id_organization FROM gems__respondent2org  " . "INNER JOIN gems__respondents WHERE gr2o_id_user = grs_id_user AND grs_email = ?", $login_name);
         if ($rows) {
             foreach ($rows as $row) {
                 $wheres[] = $this->db->quoteInto('gul_login = ? AND ', $row['gr2o_patient_nr']) . $this->db->quoteInto('gul_id_organization = ?', $row['gr2o_id_organization']);
             }
         }
     }
     // Add search fields
     $select->where(new \Zend_Db_Expr('(' . implode(') OR (', $wheres) . ')'));
     // \MUtil_Echo::track($select->__toString());
     return $select;
 }
コード例 #21
0
 /**
  * Removes all markup from input
  *
  * @param string $text Input possibly containing html
  * @return string
  */
 public function removeMarkup($text)
 {
     return \MUtil_String::beforeChars(\MUtil_Html::removeMarkup($text, 'b|i|u|em|strong'), '{');
 }
コード例 #22
0
 /**
  * Returns true if and only if $value meets the validation requirements
  *
  * If $value fails validation, then this method returns false, and
  * getMessages() will return an array of messages that explain why the
  * validation failed.
  *
  * @param  mixed $value
  * @param  array $context
  * @return boolean
  * @throws \Zend_Validate_Exception If validation of $value is impossible
  */
 public function isValid($value, $context = array())
 {
     $this->_setValue($value);
     foreach ($context as $field => $val) {
         if (\MUtil_String::startsWith($field, 'survey__')) {
             $sid = intval(substr($field, 8));
             if ($sid !== $this->_surveyId && $value == $val) {
                 $this->_error(self::ERROR_RECORD_FOUND);
                 return false;
             }
             $this->_tested[] = $sid;
         }
     }
     $result = $this->_query($value);
     if ($result) {
         $this->_error(self::ERROR_RECORD_FOUND);
         return false;
     }
     return true;
 }
コード例 #23
0
 /**
  * Output for browsing rols
  *
  * @param array $privileges
  * @return array
  */
 public function formatLongLine(array $privileges)
 {
     $output = \MUtil_Html::create('div');
     if (count($privileges)) {
         $privileges = array_combine($privileges, $privileges);
         foreach ($this->getUsedPrivileges() as $privilege => $description) {
             if (isset($privileges[$privilege])) {
                 if (count($output) > 11) {
                     $output->append('...');
                     return $output;
                 }
                 if (\MUtil_String::contains($description, '<br/>')) {
                     $description = substr($description, 0, strpos($description, '<br/>') - 1);
                 }
                 $output->raw($description);
                 $output->br();
             }
         }
     }
     return $output;
 }
コード例 #24
0
ファイル: File.php プロジェクト: GemsTracker/MUtil
 /**
  * Is the path a rooted path?
  * On Windows this does not require a drive letter, but one is allowed
  *
  * Check OS specific plus check for urls
  *
  * @param string $path
  * @return boolean
  */
 public static function isRootPath($path)
 {
     if (!$path) {
         return false;
     }
     // Quick checkes first and then something just in case
     if ('\\' == $path[0] || '/' == $path[0] || \MUtil_String::startsWith($path, DIRECTORY_SEPARATOR)) {
         return true;
     }
     // One more check for windows
     if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
         return preg_match('#^[a-zA-Z]:\\\\#', $path);
     }
     // The check for uri's (frp, http, https
     return preg_match('#^[a-zA-Z]+://#', $path);
 }
コード例 #25
0
 /**
  * Converting the field value when saving to a respondent track
  *
  * @param array $currentValue The current value
  * @param array $fieldData The other values loaded so far
  * @return mixed the new value
  */
 public function onFieldDataSave($currentValue, array $fieldData)
 {
     if (null === $currentValue || $currentValue instanceof \Zend_Db_Expr || \MUtil_String::startsWith($currentValue, 'current_', true)) {
         return $currentValue;
     }
     $saveFormat = $this->getStorageFormat();
     if ($currentValue instanceof \Zend_Date) {
         return $currentValue->toString($saveFormat);
     } else {
         $displayFormat = \MUtil_Model_Bridge_FormBridge::getFixedOption('date', 'dateFormat');
         $returnDate = \MUtil_Date::format($currentValue, $saveFormat, $displayFormat);
         if (is_null($returnDate)) {
             if (\Zend_Date::isDate($currentValue, $saveFormat)) {
                 return $currentValue;
             }
         }
         return $returnDate;
     }
     return (string) $currentValue;
 }