예제 #1
0
 public function __construct(StringObject $string, $offset, $brackets = '{}')
 {
     $this->string = $string;
     $this->offset = $offset;
     $this->match = null;
     $this->length = 0;
     list($opener, $closer) = str_split($brackets, 1);
     if (strpos($string->raw, $opener, $this->offset) === false) {
         return;
     }
     if (substr_count($string->raw, $opener) !== substr_count($string->raw, $closer)) {
         $sample = substr($string->raw, $this->offset, 25);
         warning("Unmatched token near '{$sample}'.");
         return;
     }
     $patt = $opener === '{' ? Regex::$patt->block : Regex::$patt->parens;
     if (preg_match($patt, $string->raw, $m, PREG_OFFSET_CAPTURE, $this->offset)) {
         $this->match = $m;
         $this->matchLength = strlen($m[0][0]);
         $this->matchStart = $m[0][1];
         $this->matchEnd = $this->matchStart + $this->matchLength;
         $this->length = $this->matchEnd - $this->offset;
     } else {
         warning("Could not match '{$opener}'. Exiting.");
     }
 }
예제 #2
0
파일: user.php 프로젝트: prymribb/starter
function requireUser($b = true)
{
    if ($b && !isLoggedIn()) {
        warning('You need to login to view this page.');
        redirect($GLOBALS['sLoginPage'] . '?ref=' . str_replace('?logout=true', '', $_SERVER['REQUEST_URI']));
    }
}
예제 #3
0
 /**
  * Use Facebook::configure() to initialize the facebook instance.
  *
  * @param string $appId
  * @param string $appSecret
  * @param array $options
  */
 function __construct($appId, $appSecret, $permissions = array(), $options = array())
 {
     $this->appId = $appId;
     $this->appSecret = $appSecret;
     if (is_array($permissions)) {
         $permissions = implode(',', $permissions);
     }
     $this->requiredPermissions = $permissions;
     $state = $this->getPersistentData('state');
     if (!empty($state)) {
         $this->state = $state;
     }
     $accessToken = $this->getPersistentData('access_token');
     if (!empty($accessToken)) {
         $this->accessToken = $accessToken;
     }
     if (isset($options['ignore_session_state'])) {
         // Option to prevent the "No session started" warning.
         $ignoreSessionState = $options['ignore_session_state'];
         unset($options['ignore_session_state']);
     } else {
         $ignoreSessionState = false;
     }
     if ($ignoreSessionState == false && session_id() == false) {
         warning('No session started');
     }
     foreach ($options as $property => $value) {
         $this->{$property} = $value;
     }
     $this->logger = new Logger(array('identifier' => 'Facebook', 'singular' => 'request', 'plural' => 'requests', 'renderer' => 'Sledgehammer\\Facebook::renderLog', 'columns' => array('Method', 'Request', 'Duration')));
 }
 /** Possible actions for a caller: delete */
 function percentile_actions($percentile_id)
 {
     $CI =& get_instance();
     $edit_link = anchor('percentile/edit/' . $percentile_id, img_edit());
     $delete_link = anchor('percentile/delete/' . $percentile_id, img_delete(), warning(lang('sure_delete_percentile')));
     return implode(' ', array($edit_link, $delete_link));
 }
 /** Possible actions for a participation: prioritize and delete */
 function participation_actions($participation_id)
 {
     $CI =& get_instance();
     $pp = $CI->participationModel->get_participation_by_id($participation_id);
     $not_cancelled = $pp->cancelled == 0;
     $is_confirmed = $pp->confirmed == 1 && $not_cancelled;
     $not_completed = $is_confirmed && $pp->noshow == 0 && $pp->completed == 0;
     $is_noshow = $pp->noshow == 1;
     $is_completed = $pp->completed == 1;
     $after_now = input_datetime($pp->appointment) > input_datetime('now');
     $get_link = participation_get_link($pp);
     $cancel_link = $not_completed && $not_cancelled ? anchor('participation/cancel/' . $pp->id, img_cancel(lang('cancelled'))) : img_cancel(lang('cancelled'), TRUE);
     $reschedule_link = $not_completed ? anchor('participation/reschedule/' . $pp->id, img_calendar()) : img_calendar(TRUE);
     $noshow_link = $is_confirmed && !$is_noshow && !$after_now ? anchor('participation/no_show/' . $pp->id, img_noshow()) : img_noshow(TRUE);
     $completed_link = $is_confirmed && !$after_now ? anchor('participation/completed/' . $pp->id, img_accept(lang('completed'))) : img_accept(lang('completed'), TRUE);
     $delete_link = anchor('participation/delete/' . $pp->id, img_p_delete(), warning(lang('sure_delete_part')));
     $comment_link = anchor('participation/edit_comment/' . $pp->id, img_comment());
     switch (current_role()) {
         case UserRole::Admin:
             $actions = array($get_link, $cancel_link, $reschedule_link, $noshow_link, $completed_link, $comment_link, $delete_link);
             break;
         case UserRole::Leader:
             $actions = array($get_link, $cancel_link, $reschedule_link, $noshow_link, $completed_link, $comment_link);
             break;
         default:
             $actions = array($get_link, $cancel_link, $reschedule_link, $comment_link);
             break;
     }
     return implode(' ', $actions);
 }
예제 #6
0
 protected static function resolveDocRoot($doc_root = null)
 {
     // Get document_root reference
     // $_SERVER['DOCUMENT_ROOT'] is unreliable in certain CGI/Apache/IIS setups
     if (!$doc_root) {
         $script_filename = $_SERVER['SCRIPT_FILENAME'];
         $script_name = $_SERVER['SCRIPT_NAME'];
         if ($script_filename && $script_name) {
             $len_diff = strlen($script_filename) - strlen($script_name);
             // We're comparing the two strings so normalize OS directory separators
             $script_filename = str_replace('\\', '/', $script_filename);
             $script_name = str_replace('\\', '/', $script_name);
             // Check $script_filename ends with $script_name
             if (substr($script_filename, $len_diff) === $script_name) {
                 $path = substr($script_filename, 0, $len_diff);
                 $doc_root = realpath($path);
             }
         }
         if (!$doc_root) {
             $doc_root = realpath($_SERVER['DOCUMENT_ROOT']);
         }
         if (!$doc_root) {
             warning("Could not get a valid DOCUMENT_ROOT reference.");
         }
     }
     return Util::normalizePath($doc_root);
 }
예제 #7
0
 public function __constructor()
 {
     if (func_get_args()) {
         $this->parent = func_get_arg(0);
     } else {
         $this->parent = new client();
     }
     //record a "menu interface" in object client
     //$this->_namespace = \get_constant('\platform\config\interfac3::_namespace');
     //$this->{$this->_namespace} = empty_object();
     //load template
     $this->_template_namespace = \get_constant('\\platform\\config\\template::_namespace');
     $this->{$this->_template_namespace} = new template($this);
     //load components
     $this->load_components();
     //get array of allowed interfaces, depends on role (mode)
     $access_list = '\\platform\\config\\interfac3::_a_' . $_SESSION['mode'];
     if (is_defined($access_list)) {
         $allowed_interfaces = \get_constant($access_list);
     } else {
         \error('interfac3', 'e001');
     }
     foreach ($allowed_interfaces as $interface) {
         //record a sub object for "menu interface" in object client
         //$this->{$this->_namespace}->{$interface} = empty_object();
         //if interface exists, generate interface
         if (is_defined('\\platform\\config\\interfac3::_i_' . $interface)) {
             new interfac3($this, $interface);
         } else {
             \warning('interfac3', 'e002', $interface);
         }
     }
 }
 /** Possible actions for a language: prioritize and delete */
 function language_actions($language_id)
 {
     $CI =& get_instance();
     $c = $CI->languageModel->get_language_by_id($language_id);
     $d_link = anchor('language/delete/' . $c->id, img_delete(), warning(lang('sure_delete_language')));
     return $d_link;
 }
 /** Possible actions for a testsurvey: edit, view scores, delete */
 function testsurvey_actions($testsurvey_id)
 {
     $inspect_link = anchor('testsurvey/get/' . $testsurvey_id, img_zoom('testsurvey'));
     $find_link = anchor('testsurvey/find/' . $testsurvey_id, img_email(lang('testinvite')));
     $edit_link = anchor('testsurvey/edit/' . $testsurvey_id, img_edit());
     $delete_link = anchor('testsurvey/delete/' . $testsurvey_id, img_delete(), warning(lang('sure_delete_testsurvey')));
     return implode(' ', array($inspect_link, $find_link, $edit_link, $delete_link));
 }
예제 #10
0
 /**
  * @param string $model   (required)
  * @param array  $values
  * @param array  $options array(
  *                        'repository' => (string) "default"
  *                        )
  *
  * @return SimpleRecord
  */
 public static function create($model = null, $values = [], $options = [])
 {
     if (count(func_get_args()) < 2) {
         warning('SimpleRecord::create() requires minimal 1 parameter', 'SimpleRecord::create($model, $values = [], $options = []');
     }
     $options['model'] = $model;
     return parent::create($values, $options);
 }
예제 #11
0
 /** Possible actions for a testcat: edit, show scores and delete */
 function testcat_actions($testcat_id)
 {
     $CI =& get_instance();
     $scores = $CI->scoreModel->get_scores_by_testcat($testcat_id);
     $edit_link = anchor('testcat/edit/' . $testcat_id, img_edit());
     $score_link = count($scores) > 0 ? anchor('score/testcat/' . $testcat_id, img_scores()) : img_scores(TRUE);
     $delete_link = anchor('testcat/delete/' . $testcat_id, img_delete(), warning(lang('sure_delete_testcat')));
     return implode(' ', array($edit_link, $score_link, $delete_link));
 }
예제 #12
0
 /** Possible actions for a user: edit, view participants, call, archive, delete */
 function user_actions($user_id)
 {
     $CI =& get_instance();
     $u = $CI->userModel->get_user_by_id($user_id);
     $edit_link = anchor('user/edit/' . $u->id, img_edit());
     $act_link = is_activated($u) ? anchor('user/deactivate/' . $u->id, img_active(TRUE)) : anchor('user/activate/' . $u->id, img_active(FALSE));
     $delete_link = is_admin($u) ? img_delete(TRUE) : anchor('user/delete/' . $u->id, img_delete(), warning(lang('sure_delete_user')));
     return implode(' ', array($edit_link, $act_link, $delete_link));
 }
예제 #13
0
	/**
	 *
	 * @param mixed   $value
	 * @param array   $column
	 * @param string  $msg_prefix
	 * @return boolean
	 */
	function beforesave_not_empty($value, array $column, $msg_prefix) {

		if (!$value) {
			warning($msg_prefix."The field ".$column[0]." must be not empty!");
			return false;
		}

		return true;
	}
예제 #14
0
 function save($filename, $contents)
 {
     if (!is_writeable($filename)) {
         warning("{$filename} not writeable!");
         return;
     }
     $fp = fopen($filename, "w");
     fwrite($fp, $contents);
     fclose($fp);
 }
예제 #15
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param int $id
  * @param ProductRepository $products
  * @param SupplierRepository $suppliers
  * @param VatRateRepository $vat_rates
  * @return Response
  */
 public function edit($id, ProductRepository $products, SupplierRepository $suppliers, VatRateRepository $vat_rates)
 {
     try {
         $product = $products->findById($id);
         return view('products.edit')->with('model', $product)->with('suppliers', $suppliers->all())->with('vat_rates', $vat_rates->all());
     } catch (ModelNotFoundException $e) {
         flash() - warning(trans('products.not_found'));
         return redirect()->route('product.index');
     }
 }
예제 #16
0
function difineTypeMessage($messageType = MESSAGE_TYPE_ERRO, $message)
{
    if ($messageType == MESSAGE_TYPE_ERRO) {
        return error($message);
    } elseif ($messageType == MESSAGE_TYPE_WARNING) {
        return warning($message);
    } else {
        return success($message);
    }
}
예제 #17
0
 public function validateObjects()
 {
     $validStates = array('new', 'retrieved', 'saved', 'deleted');
     foreach ($this->objects as $model => $objects) {
         foreach ($objects as $index => $object) {
             if (in_array($object['state'], $validStates) == false) {
                 warning('Invalid state "' . $object['state'] . '" for ' . $model . ' ' . $index);
             }
         }
     }
 }
예제 #18
0
function restrict($logged_out = false)
{
    if ($logged_out && is_logged_in()) {
        echo warning('Maaf, sepertinya Anda sudah login...', 'home');
        die;
    }
    if (!$logged_out && !is_logged_in()) {
        $info = 'Session Anda habis. Silakan login ulang.';
        echo '<script type="text/javascript">launch_info("' . $info . '")</script>';
        die;
    }
}
예제 #19
0
 /** Possible actions for a comment: prioritize and delete */
 function comment_actions($comment_id)
 {
     $CI =& get_instance();
     $c = $CI->commentModel->get_comment_by_id($comment_id);
     $p = $CI->participantModel->get_participant_by_id($c->participant_id);
     $prio_link = anchor('comment/prioritize/' . $comment_id . ($c->priority ? '/0' : ''), img_star(!$c->priority));
     $handled_link = anchor('comment/mark_handled/' . $comment_id . ($c->handled ? '/0' : ''), img_accept(lang('mark_handled'), !$c->handled));
     $edit_link = anchor('comment/edit/' . $comment_id, img_edit());
     $p_link = anchor('participant/edit/' . $c->participant_id, img_edit_participant($p));
     $d_link = anchor('comment/delete/' . $comment_id, img_delete(), warning(lang('sure_delete_comment')));
     return implode(' ', array($prio_link, $handled_link, $edit_link, $p_link, $d_link));
 }
예제 #20
0
/**
 * Wrapper around PHP setcookie function to automatically set some
 * DOMjudge specific defaults and check the return value.
 * - cookies are defined in a common path for all web interfaces
 */
function dj_setcookie($name, $value = null, $expire = 0, $path = null, $domain = null, $secure = false, $httponly = false)
{
    if (!isset($path)) {
        // KLUDGE: We want to find the DOMjudge base path, but this
        // information is not directly available as configuration, so
        // we extract it from the executed PHP script.
        $path = preg_replace('/(jury|public|team)\\/?$/', '', dirname($_SERVER['PHP_SELF']));
    }
    $ret = setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
    if ($ret !== true) {
        warning("Cookie '{$name}' not set properly.");
    }
    logmsg(LOG_DEBUG, "Cookie set: {$name}={$value}, expire={$expire}, path={$path}");
    return $ret;
}
예제 #21
0
/**
 * action used for GET and POST
 *
 * @param string  $code
 */
function action_confirm_mail($code) {
	if (
		Login::$member->mail_code == trim($code) and
		strtotime(Login::$member->mail_code_expiry) > time()
	) {
		Login::$member->mail = Login::$member->mail_unconfirmed;
		Login::$member->mail_unconfirmed = null;
		Login::$member->mail_code        = null;
		Login::$member->mail_code_expiry = null;
		Login::$member->mail_lock_expiry = null;
		Login::$member->update(['mail', 'mail_unconfirmed', 'mail_code', 'mail_code_expiry', 'mail_lock_expiry']);
		success(_("Your email address is confirmed now."));
		redirect("settings.php");
	}
	warning(_("The confirmation code is not valid!"));
}
예제 #22
0
 public function set_template($template)
 {
     $check = $this->device_exists($_SESSION['device']);
     if ($check !== 1) {
         warning('env', 'e001', $_SESSION['device'], $check);
         warning('env', 'Fallback to "computer"');
         $_SESSION['device'] = 'computer';
     }
     $check2 = $this->template_exists($_SESSION['device'], $template);
     if ($check2 !== 1) {
         warning('env', 'There is no template "' . $template . '" for "' . $_SESSION['device'] . '". Possible choices are : "' . $check2 . '"');
         warning('env', 'Fallback to "public"');
         $template = 'public';
     }
     $this->address = $_SESSION['device'];
 }
예제 #23
0
 public static function open()
 {
     // connect
     $error_msg = null;
     define('SESSION_DB_LINK', sqlite_open(DIR_DATA . '/sessions.db', 0666, $error_msg));
     if (!SESSION_DB_LINK) {
         warning("Can't open session database: {$error_msg}");
         return false;
     }
     // check if required table exists, create it if necessary
     $R = sqlite_query("SELECT name FROM sqlite_master WHERE type='table' AND name='sess'", SESSION_DB_LINK);
     if (!sqlite_num_rows($R)) {
         sqlite_exec("CREATE TABLE sess (id TEXT, data TEXT, expire INT)", SESSION_DB_LINK);
     }
     return true;
 }
예제 #24
0
파일: scan.php 프로젝트: guillaum3f/codie
function stack_folder($path, $namespace, $mask = null)
{
    //record the folder path containing libs
    try {
        $directory = new \DirectoryIterator($path);
    } catch (Exception $e) {
        warning('filesystem', 'e001', $path);
        return;
    }
    //format eventual namespace
    //if namespace exist push namespace in stack as new javascript object
    if ($namespace != '') {
        $namespace = trim($namespace, '.');
        get_transmission()->stack('if(!' . $namespace . '){' . $namespace . ' = {};}');
        $namespace = $namespace . '.';
    }
    //scan the folder
    //exit if there is NO item, item is NOT (a folder or a file), item IS "dot" folder
    foreach ($directory as $object) {
        //get path of item
        $pathname = $object->getPathname();
        if ($object->isDir() && !$object->isDot()) {
            //get foldername
            $foldername = $object->getBasename();
            //build new namespace
            $newnamespace = $namespace . $foldername;
            //send new path and new namespace back to the function
            stack_folder($pathname, $newnamespace);
        } else {
            if ($object->isFile()) {
                //apply mask rule
                if ($mask) {
                    if (!preg_match('#' . $mask . '#', $pathname)) {
                        continue;
                    }
                }
                //get file content
                $filecontent = get_file($pathname);
                //add $namespace to the beginning of file content
                $filecontent = $namespace . $filecontent;
                //push javascript object with new namespace in stack
                get_transmission()->stack($filecontent);
            }
        }
    }
}
예제 #25
0
 /** Returns the call image for a single participant */
 function img_call_p($participant, $experiment_id, $weeks_ahead = WEEKS_AHEAD)
 {
     // Check if the participant is currently locked
     $CI =& get_instance();
     $participation = $CI->participationModel->get_participation($experiment_id, $participant->id);
     if ($CI->participationModel->is_locked($participation)) {
         $current_call = $CI->callModel->last_call($participation->id);
         $user = $CI->callModel->get_user_by_call($current_call->id);
         $img = img(array('src' => 'images/phone_sound.png', 'title' => sprintf(lang('in_conversation'), name($participant))));
         $warning = warning(sprintf(lang('take_over_warning'), name($participant), $user->username));
         $result = anchor('call/take_over/' . $current_call->id, $img, $warning);
     } else {
         $img = img(array('src' => 'images/phone.png', 'title' => sprintf(lang('call_participant'), name($participant))));
         $result = anchor('participation/call/' . $participant->id . '/' . $experiment_id . '/' . $weeks_ahead, $img);
     }
     return $result;
 }
예제 #26
0
 public function translate()
 {
     $content = $this->flux;
     $pattern = '/__.*__/';
     $translated = preg_replace_callback($pattern, function ($matches) {
         foreach ($matches as $key => $value) {
             foreach ($matches as $value) {
                 if (array_key_exists($value, $this->terms)) {
                     return $this->terms[$value];
                 } else {
                     warning('translate', 'e001', $value);
                     return $value;
                 }
             }
         }
     }, $content);
     return $translated;
 }
예제 #27
0
 /**
  * Get a property or fields value.
  *
  * @param string $property
  *
  * @return mixed
  */
 public function __get($property)
 {
     if (property_exists($this->instance, $property)) {
         if (array_key_exists($property, $this->fields)) {
             notice('Property "' . $property . '" is ambiguous. It\'s available in both the instance as the junction fields.', "To modify the mapping of the junction field change the value of \$ModelConfig->hasMany[\$relation]['fields']['" . $property . "']");
         }
         return $this->instance->{$property};
     }
     if (array_key_exists($property, $this->fields)) {
         return $this->fields[$property];
     }
     if ($this->dynamicFields) {
         $this->fields[$property] = null;
         return;
     }
     $properties = \Sledgehammer\reflect_properties($this->instance);
     $properties['public'] = array_merge($properties['public'], $this->fields);
     warning('Property "' . $property . '" doesn\'t exist in a ' . get_class($this) . ' (' . get_class($this->instance) . ') object', \Sledgehammer\build_properties_hint($properties));
 }
예제 #28
0
 /**
  * @param array $options array('integers_only' => bool, 'minimum' => number, 'maximum' => number)
  */
 function __construct($options = array())
 {
     foreach ($options as $option => $value) {
         switch ($option) {
             case 'integers_only':
                 $this->integers_only = $value;
                 break;
             case 'minimum':
                 $this->minimum = $value;
                 break;
             case 'maximum':
                 $this->maximum = $value;
                 break;
             default:
                 warning('Unexpected option: "' . $option . '", value: "' . $value . '"');
                 break;
         }
     }
 }
 /** Possible actions for a testinvite: edit, view scores, delete */
 function testinvite_actions($testinvite_id)
 {
     $CI =& get_instance();
     $testinvite = $CI->testInviteModel->get_testinvite_by_id($testinvite_id);
     $scores = $CI->scoreModel->get_scores_by_testinvite($testinvite_id);
     $reminder_available = !$testinvite->datecompleted && $testinvite->datereminder;
     $reminder_link = anchor('testinvite/manual_reminder/' . $testinvite_id, img_email(lang('manual_reminder'), FALSE));
     $score_link = anchor('score/testinvite/' . $testinvite_id, img_scores(empty($scores)));
     $reminder_link = $reminder_available ? $reminder_link : img_email('', TRUE);
     $delete_link = anchor('testinvite/delete/' . $testinvite_id, img_delete(), warning(lang('sure_delete_testinvite')));
     if (is_caller()) {
         $actions = array($reminder_link, $delete_link);
     }
     if (is_leader()) {
         $actions = array($score_link, $reminder_link);
     }
     if (is_admin()) {
         $actions = array($score_link, $reminder_link, $delete_link);
     }
     return implode(' ', $actions);
 }
예제 #30
0
	/**
	 * encrypt password
	 *
	 * @return boolean
	 */
	function dbtableadmin_beforesave_password() {

		if ($this->id) {
			// existing admin
			if (empty($_POST['password']) and empty($_POST['password2'])) return null;
		} else {
			// new admin
			if (empty($_POST['password']) or empty($_POST['password2'])) {
				warning("The password fields must not be empty!");
				return false;
			}
		}

		if ($_POST['password'] != $_POST['password2']) {
			warning("The two password fields do not match!");
			return false;
		}

		$this->password = crypt($_POST['password']);

		return true;
	}