Example #1
0
 public static function set($conference)
 {
     $xml = FreeSwitch::setSection('conferences');
     foreach (Conference::$default_keymap as $action => $digits) {
         $xml->update('/caller-controls/group[@name="default-keymap"]/control[@action="' . $action . '"]{@digits="' . $digits . '"}');
     }
     $xml = FreeSwitch::setSection('conference_profile', $conference['conference_id']);
     $xml->deleteChildren();
     $profile = arr::merge(Conference::$default_profile, $conference['profile']);
     $registry = $conference['registry'];
     foreach ($profile as $parameter => $value) {
         $value = str_replace('/', '\\/', $value);
         if (isset($registry[$parameter])) {
             $value = $registry[$parameter];
         }
         $xml->update('/param[@name="' . $parameter . '"]{@value="' . $value . '"}');
     }
     if (!empty($registry['moh_type'])) {
         $value = str_replace('/', '\\/', $registry['moh_type']);
         $xml->update('/param[@name="moh-sound"]{@value="' . $value . '"}');
     }
     if (empty($conference['pins'])) {
         return;
     }
     foreach ($conference['pins'] as $pin) {
         if (empty($pin)) {
             continue;
         }
         $xml->update('/param[@name="pin"]{@value="' . $pin . '"}');
     }
 }
Example #2
0
 public function render($print = FALSE, $renderer = FALSE)
 {
     // Give helpers an entry to this view instance
     self::$instance = $this;
     if ($this->is_set('mustache_template') or stristr($this->kohana_filename, '.mus')) {
         if (isset($this->kohana_local_data['mustache_template']) and $this->kohana_local_data['mustache_template'] === FALSE) {
             return parent::render($print, $renderer);
         }
         $mustache_data = arr::merge(self::$kohana_global_data, $this->kohana_local_data);
         if (empty($this->kohana_local_data['mustache_partials'])) {
             $mustache_partials = array();
         } else {
             $mustache_partials = $this->kohana_local_data['mustache_partials'];
             unset($mustache_data['mustache_partials']);
         }
         $mustache = new Mustache();
         $output = $mustache->render(parent::render(FALSE), $mustache_data, $mustache_partials);
         $output = str_replace(array("\n", '  '), '', $output);
         if (!empty($this->kohana_local_data['mustache_escape_apostrophes'])) {
             $output = str_replace('\'', '\\\'', $output);
         }
         if ($print === TRUE) {
             // Display the output
             echo $output;
             return;
         }
         return $output;
     } else {
         return parent::render($print, $renderer);
     }
 }
Example #3
0
 public static function createExtension()
 {
     Event::$data += array('voicemail_password' => self::generatePin(), 'voicemail_timezone' => kohana::config('locale.timezone'), 'voicemail_email_all_messages' => empty(Event::$data['user']['email_address']) ? 0 : 1, 'voicemail_delete_file' => 0, 'voicemail_attach_audio_file' => 1, 'voicemail_email_address' => empty(Event::$data['user']['email_address']) ? '' : Event::$data['user']['email_address']);
     extract(Event::$data);
     Doctrine::getTable('Voicemail')->getRecordListener()->get('MultiTenant')->setOption('disabled', TRUE);
     $name_append = '';
     if (!empty($owner_name)) {
         $name_append = ' for ' . $owner_name;
     }
     try {
         $voicemail = new Voicemail();
         $voicemail['name'] = 'VM ' . $extension . $name_append;
         $voicemail['mailbox'] = $extension;
         $voicemail['password'] = $voicemail_password;
         $voicemail['account_id'] = $account_id;
         $voicemail['plugins'] = array('timezone' => array('timezone' => $voicemail_timezone));
         $voicemail['registry'] = array('email_all_messages' => $voicemail_email_all_messages, 'delete_file' => $voicemail_delete_file, 'attach_audio_file' => $voicemail_attach_audio_file, 'email_address' => $voicemail_email_address);
         $voicemail->save();
         $plugin = array('voicemail' => array('mwi_box' => $voicemail['voicemail_id']));
         $device['plugins'] = arr::merge($device['plugins'], $plugin);
     } catch (Exception $e) {
         Doctrine::getTable('Voicemail')->getRecordListener()->get('MultiTenant')->setOption('disabled', FALSE);
         kohana::log('error', 'Unable to generate voicemail for device: ' . $e->getMessage());
         throw $e;
     }
     Doctrine::getTable('Voicemail')->getRecordListener()->get('MultiTenant')->setOption('disabled', FALSE);
 }
Example #4
0
 public function validate(CM_Form_Abstract $form)
 {
     if ($this->_extra_validation) {
         $values = array();
         foreach ($form->get_values() as $name => $value) {
             $values[$name] = $value->get_raw();
             $this->_extra_validation->label($name, $form->get_field($name)->get_label());
         }
         // Validation только read-only, поэтому создаем новый объект
         $this->_extra_validation = $this->_extra_validation->copy($values);
     }
     try {
         $this->get_model()->check($this->_extra_validation);
     } catch (ORM_Validation_Exception $e) {
         $errors = $e->errors('validation');
         if ($external = arr::get($errors, '_external')) {
             $errors = arr::merge($errors, $external);
             unset($errors['_external']);
         }
         foreach ($errors as $name => $error) {
             $form->get_field($name)->set_error($error);
         }
         return FALSE;
     }
     return TRUE;
 }
Example #5
0
 public static function createExtension()
 {
     Event::$data += array('callerid_internal_name' => Event::$data['owner_name'], 'callerid_external_name' => Event::$data['owner_name'], 'callerid_external_number' => str_pad(Event::$data['extension'], 10, "5", STR_PAD_LEFT));
     extract(Event::$data);
     $plugin = array('callerid' => array('internal_name' => $callerid_internal_name, 'internal_number' => $extension, 'external_name' => $callerid_external_name, 'external_number' => $callerid_external_number));
     $device['plugins'] = arr::merge($device['plugins'], $plugin);
 }
Example #6
0
 public static function createExtension()
 {
     Event::$data += array('sip_username' => html::token(Event::$data['owner_name']), 'sip_password' => inflector::generatePassword());
     extract(Event::$data);
     $plugin = array('sip' => array('username' => $sip_username, 'password' => $sip_password));
     $device['plugins'] = arr::merge($device['plugins'], $plugin);
 }
Example #7
0
 public static function dropdown($data, $selected = NULL, $extra = '')
 {
     // standardize the $data as an array, strings default to the class_type
     if (!is_array($data)) {
         $data = array('name' => $data);
     }
     // add in all the defaults if they are not provided
     $defaults = array('null_option' => FALSE, 'default_first' => TRUE, 'unauth_before_auth' => FALSE);
     $data = arr::merge($defaults, $data);
     $options = array();
     $sipinterfaces = Doctrine::getTable('SipInterface')->findAll();
     foreach ($sipinterfaces as $sipinterface) {
         if (!($id = arr::get($sipinterface, 'sipinterface_id')) or !($name = arr::get($sipinterface, 'name'))) {
             continue;
         }
         if ($data['unauth_before_auth'] and !$sipinterface['auth'] or !$data['unauth_before_auth'] and $sipinterface['auth']) {
             arr::unshift_assoc($options, $id, $name);
             continue;
         }
         $options[$id] = $name;
     }
     if ($data['default_first'] and $default_sipinterface = SipInterface::get_default()) {
         unset($options[$default_sipinterface['sipinterface_id']]);
         arr::unshift_assoc($options, $default_sipinterface['sipinterface_id'], $default_sipinterface['name']);
     }
     if ($data['null_option']) {
         arr::unshift_assoc($options, 0, $data['null_option']);
     }
     $data = array_diff($data, $defaults);
     // use kohana helper to generate the markup
     return form::dropdown($data, $options, $selected, $extra);
 }
Example #8
0
 protected static function tiers_POST($id, $envelope)
 {
     if (is_null($id)) {
         self::throwErrorAndDie('Invalid request', array($id), 410);
     }
     $data = self::requireData($envelope);
     $tier_agents = array();
     if ($agents = arr::get($data, 'agents')) {
         foreach ($agents as $agent) {
             if ($tier_agent_id = arr::get($agent, 'tier_agent_id')) {
                 $tier_agent = Doctrine::getTable('TierAgent')->findOneBy('tier_agent_id', $tier_agent_id);
             } else {
                 $tier_agent = new TierAgent();
             }
             try {
                 $tier_agent->synchronizeWithArray($agent);
                 $tier_agent->save();
                 $tier_agents[] = $tier_agent->toArray();
             } catch (Exception $e) {
                 self::throwErrorAndDie('Invalid data', Bluebox_Controller::$validation->errors(), 400);
             }
         }
         arr::remove('agents', $data);
         arr::merge($envelope['data'], $data);
     }
     $response = self::generalAPI_POST($id, 'tier_id', 'Tier', $envelope);
     $response['agents'] = $tier_agents;
     return $response;
 }
Example #9
0
 public static function ignoreLogLevels($ignore)
 {
     if (!is_array($ignore)) {
         $ignore = array($ignore);
     }
     self::$ignore = arr::merge(self::$ignore, $ignore);
 }
Example #10
0
 public static function determineUninstallOrder()
 {
     self::$uninstallOrder = array();
     $dependencies = self::listDependencies();
     $catalog = Package_Catalog::getCatalog();
     foreach ($catalog as $id => $package) {
         $reliance = self::graphReliance($dependencies, $package['packageName']);
         self::$uninstallOrder = arr::merge(self::$uninstallOrder, $reliance);
     }
     self::$uninstallOrder = array_unique(self::$uninstallOrder);
     self::$uninstallOrder = array_flip(self::$uninstallOrder);
 }
 /**
  * Intialize migration library
  *
  * @param   bool   Do we want output of migration steps?
  * @param   string Database group
  */
 public function __construct($config = NULL)
 {
     $this->config = arr::merge(Kohana::$config->load('migrations')->as_array(), (array) $config);
     $database = Kohana::$config->load('database.' . Arr::get(Kohana::$config->load('migrations'), 'database', 'default'));
     // Set the driver class name
     $driver = 'Migration_Driver_' . ucfirst($database['type']);
     // Create the database connection instance
     $this->driver = new $driver(Arr::get(Kohana::$config->load('migrations'), 'database', 'default'));
     $this->driver->versions()->init();
     if (!is_dir($this->config['path'])) {
         mkdir($this->config['path'], 0777, TRUE);
     }
 }
Example #12
0
 protected function view_category($id = 1, $t = NULL)
 {
     if (!isset($this->list[$id])) {
         return array();
     }
     $result = array();
     $tmp = $this->list[$id];
     $result[$tmp['id']] = trim($t . ' ' . $tmp['title']);
     if (array_key_exists($tmp['id'], $this->parent)) {
         foreach ($this->parent[$tmp['id']] as $v) {
             $result = arr::merge($result, $this->view_category($v, $t . $this->dash));
         }
     }
     return $result;
 }
Example #13
0
File: tts.php Project: swk/bluebox
 public static function dropdown($data, $selected = NULL, $extra = '')
 {
     // standardize the $data as an array, strings default to the class_type
     if (!is_array($data)) {
         $data = array('name' => $data);
     }
     // add in all the defaults if they are not provided
     $defaults = array('nullOption' => FALSE);
     $data = arr::merge($defaults, $data);
     $options = TTSEngine::catalog();
     if ($data['nullOption']) {
         array_unshift($options, $data['nullOption']);
     }
     $data = array_diff($data, $defaults);
     // use kohana helper to generate the markup
     return form::dropdown($data, $options, $selected, $extra);
 }
Example #14
0
 /**
  * Generate Main Tab Menus (RIGHT SIDE)
  */
 public static function main_right_tabs($user = FALSE)
 {
     $main_right_tabs = array();
     // Change tabs for MHI
     if (Kohana::config('config.enable_mhi') == TRUE and Kohana::config('settings.subdomain') == '') {
         $main_right_tabs = array('users' => Kohana::lang('ui_admin.users'), 'mhi/settings' => Kohana::lang('ui_admin.settings'));
     } else {
         // Build the tabs array depending on the role permissions for each section
         if ($user) {
             // Check permissions for settings panel
             $main_right_tabs = Auth::instance()->has_permission('settings', $user) ? arr::merge($main_right_tabs, array('settings/site' => Kohana::lang('ui_admin.settings'))) : $main_right_tabs;
             // Check permissions for the manage panel
             $main_right_tabs = Auth::instance()->has_permission('manage', $user) ? arr::merge($main_right_tabs, array('manage' => Kohana::lang('ui_admin.manage'))) : $main_right_tabs;
             // Check permissions for users panel
             $main_right_tabs = Auth::instance()->has_permission('users', $user) ? arr::merge($main_right_tabs, array('users' => Kohana::lang('ui_admin.users'))) : $main_right_tabs;
         }
     }
     return $main_right_tabs;
 }
Example #15
0
 /**
  * Load addon Information from readme.txt file
  *
  * @param   string addon name
  * @param   string addon type
  * @param   array  default meta data
  * @return  array
  */
 public static function meta_data($addon, $type, $defaults = array())
 {
     $base = $type == 'plugin' ? PLUGINPATH : THEMEPATH;
     // Determine if readme.txt (Case Insensitive) exists
     $file = $base . $addon . "/readme.txt";
     if (file::file_exists_i($file, $file)) {
         $fp = fopen($file, 'r');
         // Pull only the first 8kiB of the file in.
         $file_data = fread($fp, 8192);
         fclose($fp);
         preg_match_all('/^(.*):(.*)$/mU', $file_data, $matches, PREG_PATTERN_ORDER);
         $meta_data = array_combine(array_map('trim', $matches[1]), array_map('trim', $matches[2]));
         foreach (array('png', 'gif', 'jpg', 'jpeg') as $ext) {
             if (file_exists($base . $addon . "/screenshot.{$ext}")) {
                 $meta_data['Screenshot'] = "screenshot.{$ext}";
                 break;
             }
         }
         return arr::merge($defaults, $meta_data);
     }
     return false;
 }
Example #16
0
 public function installCore(&$packages)
 {
     $core['core'] = array('version' => Bluebox_Controller::$version, 'packageName' => 'core', 'author' => 'Bluebox Team', 'vendor' => 'Bluebox', 'license' => 'MPL', 'summary' => 'Core Application', 'description' => '', 'default' => TRUE, 'type' => Bluebox_Installer::TYPE_MODULE, 'required' => array(), 'displayName' => 'System Core', 'canBeDisabled' => FALSE, 'canBeRemoved' => FALSE, 'directory' => 'bluebox', 'configureClass' => '', 'installedAs' => array('package_id' => '0', 'name' => 'core', 'display_name' => 'System Core', 'module_version' => Bluebox_Controller::$version, 'status' => 'installed', 'basedir' => 'bluebox', 'parameters' => array('version' => Bluebox_Controller::$version, 'packageName' => 'core', 'author' => 'Bluebox Team', 'vendor' => 'Bluebox', 'license' => 'MPL', 'summary' => 'Core Application', 'description' => '', 'default' => TRUE, 'type' => Bluebox_Installer::TYPE_MODULE, 'required' => array(), 'displayName' => 'System Core', 'canBeDisabled' => FALSE, 'canBeRemoved' => FALSE, 'directory' => 'bluebox', 'configureClass' => '', 'navStructures' => array())), 'models' => array(), 'created_at' => '2010-03-27 08:29:06', 'updated_at' => '2010-03-27 08:53:43', 'action' => FALSE, 'navStructures' => array());
     $packages = arr::merge($core, $packages);
 }
Example #17
0
 public function index($user_id = 0)
 {
     // Set messages to display on the login page for the user
     $message = FALSE;
     $message_class = 'login_error';
     $auth = Auth::instance();
     // If already logged in redirect to user account page
     $insufficient_role = FALSE;
     if ($auth->logged_in()) {
         // Redirect users to the relevant dashboard
         if ($auth->logged_in('login')) {
             url::redirect($auth->get_user()->dashboard());
         }
         $insufficient_role = TRUE;
         $message_class = 'login_error';
         $message = Kohana::lang('ui_main.insufficient_role');
     }
     // setup and initialize form field names
     $form = array('action' => '', 'username' => '', 'password' => '', 'password_again' => '', 'name' => '', 'email' => '', 'resetemail' => '', 'confirmation_email' => '');
     //	copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $openid_error = FALSE;
     $success = FALSE;
     $change_pw_success = FALSE;
     $new_confirm_email_form = FALSE;
     $action = isset($_POST["action"]) ? $_POST["action"] : "";
     // Override success variable if change_pw_success GET var is set
     if (isset($_GET["change_pw_success"])) {
         $change_pw_success = TRUE;
         $message_class = 'login_success';
         $message = Kohana::lang('ui_main.password_changed_successfully');
     }
     // Show send new confirm email form
     if (isset($_GET["new_confirm_email"])) {
         $new_confirm_email_form = TRUE;
         $message_class = 'login_error';
         $message = Kohana::lang('ui_main.must_confirm_email_address');
     }
     // Show send new confirm email form
     if (isset($_GET["confirmation_failure"])) {
         $new_confirm_email_form = TRUE;
         $message_class = 'login_error';
         $message = Kohana::lang('ui_main.confirm_email_failed');
     }
     // Show that confirming the email address was a success
     if (isset($_GET["confirmation_success"])) {
         $message_class = 'login_success';
         $message = Kohana::lang('ui_main.confirm_email_successful');
     }
     // Is this a password reset request? We need to show the password reset form if it is
     if (isset($_GET["reset"])) {
         $this->template->token = $this->uri->segment(4);
         $this->template->changeid = $this->uri->segment(3);
     }
     // Regular Form Post for Signin
     // check, has the form been submitted, if so, setup validation
     if ($_POST and isset($_POST["action"]) and $_POST["action"] == "signin") {
         // START: Signin Process
         $post = Validation::factory($_POST);
         $post->pre_filter('trim');
         $post->add_rules('username', 'required');
         $post->add_rules('password', 'required');
         if ($post->validate(FALSE)) {
             // Sanitize $_POST data removing all inputs without rules
             $postdata_array = $post->safe_array();
             // Flip this flag to flase to skip the login
             $valid_login = TRUE;
             // Load the user
             $user = ORM::factory('user', $postdata_array['username']);
             $remember = isset($post->remember) ? TRUE : FALSE;
             // Allow a login with username or email address, but we need to figure out which is
             // which so we can pass the appropriate variable on login. Mostly used for RiverID
             $email = $postdata_array['username'];
             if (valid::email($email) == FALSE) {
                 // Invalid Email, we need to grab it from the user account instead
                 $email = $user->email;
                 if (valid::email($email) == FALSE and kohana::config('riverid.enable') == TRUE) {
                     // We don't have any valid email for this user.
                     // Only skip login if we are authenticating with RiverID.
                     $valid_login = FALSE;
                 }
             }
             // Auth Login requires catching exceptions to properly show errors
             try {
                 $login = $auth->login($user, $postdata_array['password'], $remember, $email);
                 // Attempt a login
                 if ($login and $valid_login) {
                     // Action::user_login - User Logged In
                     Event::run('ushahidi_action.user_login', $user);
                     // Exists Redirect to Dashboard
                     url::redirect($user->dashboard());
                 } else {
                     // If user isn't confirmed, redirect to resend confirmation page
                     if (Kohana::config('settings.require_email_confirmation') and ORM::factory('user', $user)->confirmed == 0) {
                         url::redirect("login?new_confirm_email");
                     }
                     // Generic Error if exception not passed
                     $post->add_error('password', 'login error');
                 }
             } catch (Exception $e) {
                 $error_message = $e->getMessage();
                 // We use a "custom" message because of RiverID.
                 $post->add_error('password', $error_message);
             }
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             // We need to already have created an error message file, for Kohana to use
             // Pass the error message file name to the errors() method
             $errors = arr::merge($errors, $post->errors('auth'));
             $form_error = TRUE;
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             // We need to already have created an error message file, for Kohana to use
             // Pass the error message file name to the errors() method
             $errors = arr::merge($errors, $post->errors('auth'));
             $form_error = TRUE;
         }
         // END: Signin Process
     } elseif ($_POST and isset($_POST["action"]) and $_POST["action"] == "new") {
         // START: New User Process
         $post = Validation::factory($_POST);
         //	Add some filters
         $post->pre_filter('trim', TRUE);
         $post->add_rules('password', 'required', 'length[' . kohana::config('auth.password_length') . ']', 'alpha_dash');
         $post->add_rules('name', 'required', 'length[3,100]');
         $post->add_rules('email', 'required', 'email', 'length[4,64]');
         $post->add_callbacks('username', array($this, 'username_exists_chk'));
         $post->add_callbacks('email', array($this, 'email_exists_chk'));
         // If Password field is not blank
         if (!empty($post->password)) {
             $post->add_rules('password', 'required', 'length[' . kohana::config('auth.password_length') . ']', 'alpha_dash', 'matches[password_again]');
         }
         //pass the post object to any plugins that care to know.
         Event::run('ushahidi_action.users_add_login_form', $post);
         if ($post->validate()) {
             $riverid_id = false;
             if (kohana::config('riverid.enable') == true) {
                 $riverid = new RiverID();
                 $riverid->email = $post->email;
                 $riverid->password = $post->password;
                 $riverid->register();
                 $riverid_id = $riverid->user_id;
             }
             $user = User_Model::create_user($post->email, $post->password, $riverid_id, $post->name);
             //pass the new user on to any plugins that care to know
             Event::run('ushahidi_action.user_edit', $user);
             // Send Confirmation email
             $email_sent = $this->_send_email_confirmation($user);
             if ($email_sent) {
                 $message_class = 'login_success';
                 $message = Kohana::lang('ui_main.login_confirmation_sent');
             } else {
                 $message_class = 'login_success';
                 $message = Kohana::lang('ui_main.login_account_creation_successful');
             }
             $success = TRUE;
             $action = "";
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::merge($errors, $post->errors('auth'));
             $form_error = TRUE;
         }
         // END: New User Process
     } elseif ($_POST and isset($_POST["action"]) and $_POST["action"] == "forgot") {
         // START: Forgot Password Process
         $post = Validation::factory($_POST);
         //	Add some filters
         $post->pre_filter('trim', TRUE);
         $post->add_callbacks('resetemail', array($this, 'email_exists_chk'));
         if ($post->validate()) {
             $user = ORM::factory('user', $post->resetemail);
             // Existing User??
             if ($user->loaded) {
                 $email_sent = FALSE;
                 // Determine which reset method to use. The options are to use the RiverID server
                 //  or to use the normal method which just resets the password locally.
                 if (Kohana::config('riverid.enable') == TRUE and !empty($user->riverid)) {
                     // Reset on RiverID Server
                     $secret_link = url::site('login/index/' . $user->id . '/%token%?reset');
                     $message = $this->_email_resetlink_message($user->name, $secret_link);
                     $riverid = new RiverID();
                     $riverid->email = $post->resetemail;
                     $email_sent = $riverid->requestpassword($message);
                 } else {
                     // Reset locally
                     $secret = $user->forgot_password_token();
                     $secret_link = url::site('login/index/' . $user->id . '/' . urlencode($secret) . '?reset');
                     $email_sent = $this->_email_resetlink($post->resetemail, $user->name, $secret_link);
                 }
                 if ($email_sent == TRUE) {
                     $message_class = 'login_success';
                     $message = Kohana::lang('ui_main.login_confirmation_sent');
                 } else {
                     $message_class = 'login_error';
                     $message = Kohana::lang('ui_main.unable_send_email');
                 }
                 $success = TRUE;
                 $action = "";
             }
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::merge($errors, $post->errors('auth'));
             $form_error = TRUE;
         }
         // END: Forgot Password Process
     } elseif ($_POST and isset($_POST["action"]) and $_POST["action"] == "changepass") {
         // START: Password Change Process
         $post = Validation::factory($_POST);
         //	Add some filters
         $post->pre_filter('trim', TRUE);
         $post->add_rules('token', 'required');
         $post->add_rules('changeid', 'required');
         $post->add_rules('password', 'required', 'length[' . Kohana::config('auth.password_length') . ']', 'alpha_dash');
         $post->add_rules('password', 'required', 'length[' . Kohana::config('auth.password_length') . ']', 'alpha_dash', 'matches[password_again]');
         if ($post->validate()) {
             $success = $this->_new_password($post->changeid, $post->password, $post->token);
             if ($success == TRUE) {
                 // We don't need to see this page anymore if we were successful. We want to go
                 //   to the login form and let the user know that they were successful at
                 //   changing their password
                 url::redirect("login?change_pw_success");
                 exit;
             }
             $post->add_error('token', 'invalid');
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::merge($errors, $post->errors('auth'));
             $form_error = TRUE;
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::merge($errors, $post->errors('auth'));
             $form_error = TRUE;
         }
         // END: Password Change Process
     } elseif ($_POST and isset($_POST["action"]) and $_POST["action"] == "resend_confirmation") {
         // START: Confirmation Email Resend Process
         $post = Validation::factory($_POST);
         //	Add some filters
         $post->pre_filter('trim', TRUE);
         $post->add_callbacks('confirmation_email', array($this, 'email_exists_chk'));
         if ($post->validate()) {
             $user = ORM::factory('user', $post->confirmation_email);
             if ($user->loaded) {
                 // Send Confirmation email
                 $email_sent = $this->_send_email_confirmation($user);
                 if ($email_sent) {
                     $message_class = 'login_success';
                     $message = Kohana::lang('ui_main.login_confirmation_sent');
                     $success = TRUE;
                 } else {
                     $message_class = 'login_error';
                     $message = Kohana::lang('ui_main.unable_send_email');
                     $success = FALSE;
                 }
             } else {
                 // ERROR: User doesn't exist
                 $message_class = 'login_error';
                 $message = Kohana::lang('ui_main.login_email_doesnt_exist');
                 $success = FALSE;
             }
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::merge($errors, $post->errors('auth'));
             $form_error = TRUE;
         }
     }
     // Only if we allow OpenID, should we even try this
     if (Kohana::config('config.allow_openid') == TRUE) {
         // START: OpenID Shenanigans
         // OpenID Post
         try {
             $openid = new OpenID();
             // Retrieve the Name (if available) and Email
             $openid->required = array("namePerson", "contact/email");
             if (!$openid->mode) {
                 if (isset($_POST["openid_identifier"])) {
                     $openid->identity = $_POST["openid_identifier"];
                     header("Location: " . $openid->authUrl());
                 }
             } elseif ($openid->mode == "cancel") {
                 $openid_error = TRUE;
                 $message_class = 'login_error';
                 $message = "You have canceled authentication!";
             } else {
                 if ($openid->validate()) {
                     // Does User Exist?
                     $openid_user = ORM::factory("openid")->where("openid", $openid->identity)->find();
                     if ($openid_user->loaded and $openid_user->user) {
                         // First log all other sessions out
                         $auth->logout();
                         // Initiate Ushahidi side login + AutoLogin
                         $auth->force_login($openid_user->user->username);
                         // Exists Redirect to Dashboard
                         url::redirect($user->dashboard());
                     } else {
                         // Does this openid have the required email??
                         $new_openid = $openid->getAttributes();
                         if (!isset($new_openid["contact/email"]) or empty($new_openid["contact/email"])) {
                             $openid_error = TRUE;
                             $message_class = 'login_error';
                             $message = $openid->identity . " has not been logged in. No Email Address Found.";
                         } else {
                             // Create new User and save OpenID
                             $user = ORM::factory("user");
                             // But first... does this email address already exist
                             // in the system?
                             if ($user->email_exists($new_openid["contact/email"])) {
                                 $openid_error = TRUE;
                                 $message_class = 'login_error';
                                 $message = $new_openid["contact/email"] . " is already registered in our system.";
                             } else {
                                 $username = "******" . time();
                                 // Random User Name from TimeStamp - can be changed later
                                 $password = text::random("alnum", 16);
                                 // Create Random Strong Password
                                 // Name Available?
                                 $user->name = (isset($new_openid["namePerson"]) and !empty($new_openid["namePerson"])) ? $new_openid["namePerson"] : $username;
                                 $user->username = $username;
                                 $user->password = $password;
                                 $user->email = $new_openid["contact/email"];
                                 // Add New Roles
                                 $user->add(ORM::factory('role', 'login'));
                                 $user->add(ORM::factory('role', 'member'));
                                 $user->save();
                                 // Save OpenID and Association
                                 $openid_user->user_id = $user->id;
                                 $openid_user->openid = $openid->identity;
                                 $openid_user->openid_email = $new_openid["contact/email"];
                                 $openid_user->openid_server = $openid->server;
                                 $openid_user->openid_date = date("Y-m-d H:i:s");
                                 $openid_user->save();
                                 // Initiate Ushahidi side login + AutoLogin
                                 $auth->login($username, $password, TRUE);
                                 // Redirect to Dashboard
                                 url::redirect($user->dashboard());
                             }
                         }
                     }
                 } else {
                     $openid_error = TRUE;
                     $message_class = 'login_error';
                     $message = $openid->identity . "has not been logged in.";
                 }
             }
         } catch (ErrorException $e) {
             $openid_error = TRUE;
             $message_class = 'login_error';
             $message = $e->getMessage();
         }
         // END: OpenID Shenanigans
     }
     // Set the little badge under the form informing users that their logins are being managed
     //   by an external service.
     $this->template->riverid_information = '';
     if (kohana::config('riverid.enable') == TRUE) {
         $riverid = new RiverID();
         $this->template->riverid_information = Kohana::lang('ui_main.riverid_information', $riverid->name);
         $this->template->riverid_url = $riverid->url;
     }
     $this->template->errors = $errors;
     $this->template->success = $success;
     $this->template->change_pw_success = $change_pw_success;
     $this->template->form = $form;
     $this->template->form_error = $form_error;
     $this->template->new_confirm_email_form = $new_confirm_email_form;
     // Message to user
     $this->template->message_class = $message_class;
     $this->template->message = $message;
     // This just means the user isn't a member or an admin, so they have nowhere to go, but they are logged in.
     $this->template->insufficient_role = $insufficient_role;
     $this->template->site_name = Kohana::config('settings.site_name');
     $this->template->site_tagline = Kohana::config('settings.site_tagline');
     // Javascript Header
     $this->template->js = new View('login/login_js');
     $this->template->js->action = $action;
     // Header Nav
     $header_nav = new View('header_nav');
     $this->template->header_nav = $header_nav;
     $this->template->header_nav->loggedin_user = FALSE;
     if (isset(Auth::instance()->get_user()->id)) {
         // Load User
         $this->template->header_nav->loggedin_role = Auth::instance()->get_user()->dashboard();
         $this->template->header_nav->loggedin_user = Auth::instance()->get_user();
     }
     $this->template->header_nav->site_name = Kohana::config('settings.site_name');
 }
Example #18
0
 /**
  * Emulates array_merge_recursive, but appends numeric keys and replaces
  * associative keys, instead of appending all keys.
  *
  * @param   array  any number of arrays
  * @return  array
  */
 public static function merge()
 {
     $total = func_num_args();
     $result = array();
     for ($i = 0; $i < $total; $i++) {
         foreach (func_get_arg($i) as $key => $val) {
             if (isset($result[$key])) {
                 if (is_array($val)) {
                     // Arrays are merged recursively
                     $result[$key] = arr::merge($result[$key], $val);
                 } elseif (is_int($key)) {
                     // Indexed arrays are appended
                     array_push($result, $val);
                 } else {
                     // Associative arrays are replaced
                     $result[$key] = $val;
                 }
             } else {
                 // New values are added
                 $result[$key] = $val;
             }
         }
     }
     return $result;
 }
Example #19
0
 /**
  * Download Reports in CSV format
  */
 public function download()
 {
     // If user doesn't have access, redirect to dashboard
     if (!$this->auth->has_permission("reports_download")) {
         url::redirect(url::site() . 'admin/dashboard');
     }
     $this->template->content = new View('admin/reports/download');
     $this->template->content->title = Kohana::lang('ui_admin.download_reports');
     $errors = $form = array('format' => '', 'data_active' => array(), 'data_verified' => array(), 'data_include' => array(), 'from_date' => '', 'to_date' => '', 'form_auth_token' => '');
     // Default to all selected
     $form['data_active'] = array(0, 1);
     $form['data_verified'] = array(0, 1);
     $form['data_include'] = array(1, 2, 3, 4, 5, 6, 7);
     $form_error = FALSE;
     // Check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
         $post = array_merge($_POST, $_FILES);
         // Test to see if things passed the rule checks
         if (download::validate($post)) {
             // Set filter
             $filter = '( ';
             // Report Type Filter
             $show_active = FALSE;
             $show_inactive = FALSE;
             $show_verified = FALSE;
             $show_not_verified = FALSE;
             if (in_array(1, $post->data_active)) {
                 $show_active = TRUE;
             }
             if (in_array(0, $post->data_active)) {
                 $show_inactive = TRUE;
             }
             if (in_array(1, $post->data_verified)) {
                 $show_verified = TRUE;
             }
             if (in_array(0, $post->data_verified)) {
                 $show_not_verified = TRUE;
             }
             // Handle active or not active
             if ($show_active && !$show_inactive) {
                 $filter .= ' incident_active = 1 ';
             } elseif (!$show_active && $show_inactive) {
                 $filter .= '  incident_active = 0 ';
             } elseif ($show_active && $show_inactive) {
                 $filter .= ' (incident_active = 1 OR incident_active = 0) ';
             } elseif (!$show_active && !$show_inactive) {
                 // Equivalent to 1 = 0
                 $filter .= ' (incident_active = 0 AND incident_active = 1) ';
             }
             $filter .= ' AND ';
             // Handle verified
             if ($show_verified && !$show_not_verified) {
                 $filter .= ' incident_verified = 1 ';
             } elseif (!$show_verified && $show_not_verified) {
                 $filter .= ' incident_verified = 0 ';
             } elseif ($show_verified && $show_not_verified) {
                 $filter .= ' (incident_verified = 0 OR incident_verified = 1) ';
             } elseif (!$show_verified && !$show_not_verified) {
                 $filter .= ' (incident_verified = 0 AND incident_verified = 1) ';
             }
             $filter .= ') ';
             // Report Date Filter
             if (!empty($post->from_date)) {
                 $filter .= " AND incident_date >= '" . date("Y-m-d H:i:s", strtotime($post->from_date)) . "' ";
             }
             if (!empty($post->to_date)) {
                 $filter .= " AND incident_date <= '" . date("Y-m-d H:i:s", strtotime($post->to_date)) . "' ";
             }
             // Retrieve reports
             $incidents = ORM::factory('incident')->where($filter)->orderby('incident_dateadd', 'desc')->find_all();
             // Retrieve categories
             $categories = Category_Model::get_categories(FALSE, FALSE, FALSE);
             // Retrieve Forms
             $forms = ORM::Factory('form')->find_all();
             // Retrieve Custom forms
             $custom_forms = customforms::get_custom_form_fields();
             // If CSV format is selected
             if ($post->format == 'csv') {
                 $report_csv = download::download_csv($post, $incidents, $custom_forms);
                 // Output to browser
                 header("Content-type: text/x-csv");
                 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                 header("Content-Disposition: attachment; filename=" . time() . ".csv");
                 header("Content-Length: " . strlen($report_csv));
                 echo $report_csv;
                 exit;
             }
             // If XML format is selected
             if ($post->format == 'xml') {
                 header('Content-type: text/xml; charset=UTF-8');
                 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                 header("Content-Disposition: attachment; filename=" . time() . ".xml");
                 $content = download::download_xml($post, $incidents, $categories, $forms);
                 echo $content;
                 exit;
             }
         } else {
             // Repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // Populate the error fields, if any
             $errors = arr::merge($errors, $post->errors('report'));
             $form_error = TRUE;
         }
     }
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     // Javascript Header
     $this->themes->js = new View('admin/reports/download_js');
     $this->themes->js->calendar_img = url::base() . "media/img/icon-calendar.gif";
 }
Example #20
0
 /**
  * Download Reports in CSV format
  * JP: Added filter by search option. Also added HTML download.
  */
 public function download()
 {
     // If user doesn't have access, redirect to dashboard
     if (!$this->auth->has_permission("reports_download")) {
         url::redirect(url::site() . 'admin/dashboard');
     }
     $this->template->content = new View('admin/reports/download');
     $this->template->content->title = Kohana::lang('ui_admin.download_reports');
     $errors = $form = array('format' => '', 'data_active' => array(), 'data_verified' => array(), 'data_include' => array(), 'from_date' => '', 'to_date' => '', 'form_auth_token' => '', 'filter_search' => '');
     // Default to all selected
     $form['data_active'] = array(0, 1);
     $form['data_verified'] = array(0, 1);
     $form['data_include'] = array(1, 2, 3, 4, 5, 6, 7);
     $form_error = FALSE;
     // Check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
         $post = array_merge($_POST, $_FILES);
         // Test to see if things passed the rule checks
         if (download::validate($post)) {
             // Set filter
             $filter = '( ';
             // Report Type Filter
             $show_active = FALSE;
             $show_inactive = FALSE;
             $show_verified = FALSE;
             $show_not_verified = FALSE;
             $filter_search = FALSE;
             if (in_array(1, $post->data_active)) {
                 $show_active = TRUE;
             }
             if (in_array(0, $post->data_active)) {
                 $show_inactive = TRUE;
             }
             if (in_array(1, $post->data_verified)) {
                 $show_verified = TRUE;
             }
             if (in_array(0, $post->data_verified)) {
                 $show_not_verified = TRUE;
             }
             if (!empty($post->filter_search)) {
                 $filter_search = TRUE;
             }
             // Handle active or not active
             if ($show_active && !$show_inactive) {
                 $filter .= ' incident_active = 1 ';
             } elseif (!$show_active && $show_inactive) {
                 $filter .= '  incident_active = 0 ';
             } elseif ($show_active && $show_inactive) {
                 $filter .= ' (incident_active = 1 OR incident_active = 0) ';
             } elseif (!$show_active && !$show_inactive) {
                 // Equivalent to 1 = 0
                 $filter .= ' (incident_active = 0 AND incident_active = 1) ';
             }
             $filter .= ' AND ';
             // Handle verified
             if ($show_verified && !$show_not_verified) {
                 $filter .= ' incident_verified = 1 ';
             } elseif (!$show_verified && $show_not_verified) {
                 $filter .= ' incident_verified = 0 ';
             } elseif ($show_verified && $show_not_verified) {
                 $filter .= ' (incident_verified = 0 OR incident_verified = 1) ';
             } elseif (!$show_verified && !$show_not_verified) {
                 $filter .= ' (incident_verified = 0 AND incident_verified = 1) ';
             }
             $filter .= ') ';
             // Report Date Filter
             if (!empty($post->from_date)) {
                 $filter .= " AND incident_date >= '" . date("Y-m-d H:i:s", strtotime($post->from_date)) . "' ";
             }
             if (!empty($post->to_date)) {
                 $filter .= " AND incident_date <= '" . date("Y-m-d H:i:s", strtotime($post->to_date)) . "' ";
             }
             // JP: Search Filter
             if ($filter_search) {
                 $where_string = "";
                 $or = "";
                 // Stop words that we won't search for
                 // Add words as needed!!
                 $stop_words = array('the', 'and', 'a', 'to', 'of', 'in', 'i', 'is', 'that', 'it', 'on', 'you', 'this', 'for', 'but', 'with', 'are', 'have', 'be', 'at', 'or', 'as', 'was', 'so', 'if', 'out', 'not');
                 // Phase 1 - Fetch the search string and perform initial sanitization
                 $keyword_raw = preg_replace('#/\\w+/#', '', $post->filter_search);
                 // Phase 2 - Strip the search string of any HTML and PHP tags that may be present for additional safety
                 $keyword_raw = strip_tags($keyword_raw);
                 // Phase 3 - Apply Kohana's XSS cleaning mechanism
                 $keyword_raw = $this->input->xss_clean($keyword_raw);
                 // Database instance
                 $db = new Database();
                 $keywords = explode(' ', $keyword_raw);
                 if (is_array($keywords) and !empty($keywords)) {
                     array_change_key_case($keywords, CASE_LOWER);
                     $i = 0;
                     foreach ($keywords as $value) {
                         if (!in_array($value, $stop_words) and !empty($value)) {
                             // Escape the string for query safety
                             $chunk = $db->escape_str($value);
                             if ($i > 0) {
                                 $or = ' OR ';
                             }
                             $where_string = $where_string . $or . "(incident_title LIKE '%{$chunk}%' OR incident_description LIKE '%{$chunk}%')";
                             $i++;
                         }
                     }
                 }
                 $filter .= " AND " . $where_string;
             }
             // Retrieve reports
             $incidents = ORM::factory('incident')->where($filter)->orderby('incident_dateadd', 'desc')->find_all();
             // Retrieve categories
             $categories = Category_Model::get_categories(FALSE, FALSE, FALSE);
             // Retrieve Forms
             $forms = ORM::Factory('form')->find_all();
             // Retrieve Custom forms
             $custom_forms = customforms::get_custom_form_fields();
             // If CSV format is selected
             if ($post->format == 'csv') {
                 $report_csv = download::download_csv($post, $incidents, $custom_forms);
                 // Output to browser
                 header("Content-type: text/x-csv");
                 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                 header("Content-Disposition: attachment; filename=" . time() . ".csv");
                 header("Content-Length: " . strlen($report_csv));
                 echo $report_csv;
                 exit;
             }
             // If XML format is selected
             if ($post->format == 'xml') {
                 header('Content-type: text/xml; charset=UTF-8');
                 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                 header("Content-Disposition: attachment; filename=" . time() . ".xml");
                 $content = download::download_xml($post, $incidents, $categories, $forms);
                 echo $content;
                 exit;
             }
             // JP: If HTML format is selected...
             if ($post->format == 'html') {
                 $content = download::download_html($post, $incidents, $custom_forms);
                 header("Content-type: text/html; charset=UTF-8");
                 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                 header("Content-Disposition: attachment; filename=" . time() . ".html");
                 header("Content-Length: " . strlen($content));
                 echo $content;
                 exit;
             }
         } else {
             // Repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // Populate the error fields, if any
             $errors = arr::merge($errors, $post->errors('report'));
             $form_error = TRUE;
         }
     }
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     // Javascript Header
     $this->themes->js = new View('admin/reports/download_js');
     $this->themes->js->calendar_img = url::base() . "media/img/icon-calendar.gif";
 }
Example #21
0
 protected function loadFormData()
 {
     // Get any data coming from the form for this plugin
     $this->formData = $this->input->post($this->name, array());
     // If the plugin already has data merge what came from the form
     if (isset($this->base['plugins'][$this->name])) {
         $this->pluginData = arr::merge($this->base['plugins'][$this->name], $this->formData);
     } else {
         $this->pluginData = $this->formData;
     }
     return TRUE;
 }
Example #22
0
 /**
  * Submits a new report.
  */
 public function submit($id = FALSE, $saved = FALSE)
 {
     $db = new Database();
     // First, are we allowed to submit new reports?
     if (!Kohana::config('settings.allow_reports')) {
         url::redirect(url::site() . 'main');
     }
     $this->template->header->this_page = 'reports_submit';
     $this->template->content = new View('reports/submit');
     $this->template->header->page_title .= Kohana::lang('ui_main.reports_submit_new') . Kohana::config('settings.title_delimiter');
     //Retrieve API URL
     $this->template->api_url = Kohana::config('settings.api_url');
     // Setup and initialize form field names
     // JP: added additional form data for advanced settings
     $form = array('incident_title' => '', 'incident_description' => '', 'incident_date' => '', 'incident_hour' => '', 'incident_minute' => '', 'incident_ampm' => '', 'latitude' => '', 'longitude' => '', 'geometry' => array(), 'location_name' => '', 'country_id' => '', 'country_name' => '', 'incident_category' => array(), 'incident_news' => array(), 'incident_video' => array(), 'incident_photo' => array(), 'incident_zoom' => '', 'person_first' => '', 'person_last' => '', 'person_email' => '', 'form_id' => '', 'custom_field' => array(), 'form_data' => array());
     // Copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = $saved == 'saved';
     // Initialize Default Values
     $form['incident_date'] = date("m/d/Y", time());
     $form['incident_hour'] = date('h');
     $form['incident_minute'] = date('i');
     $form['incident_ampm'] = date('a');
     $form['country_id'] = Kohana::config('settings.default_country');
     // Initialize Default Value for Hidden Field Country Name, just incase Reverse Geo coding yields no result
     $country_name = ORM::factory('country', $form['country_id']);
     $form['country_name'] = $country_name->country;
     // Initialize custom field array
     $form['form_id'] = 1;
     // JP: Removed the $form_id variable since it was being mistakenly used later as the ID of the posted form, resulting in bugs. Changed instances of $form_id to $form['form_id'] (like below) and $post['form_id'], if posted.
     $form['custom_field'] = customforms::get_custom_form_fields($id, $form['form_id'], true);
     // JP: Grab additional form information for advanced settings.
     $form['form_data'] = customforms::get_custom_form($form['form_id']);
     // GET custom forms
     $forms = array();
     foreach (customforms::get_custom_forms() as $custom_forms) {
         $forms[$custom_forms->id] = $custom_forms->form_title;
     }
     $this->template->content->forms = $forms;
     // Check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
         $post = array_merge($_POST, $_FILES);
         // JP: Ensure that the advanced settings are correct.
         $form['form_data'] = customforms::get_custom_form($post['form_id']);
         // JP: Add the description_active boolean to our post data so the appropriate validation rules can be added.
         $post['description_active'] = $form['form_data']->description_active;
         // Adding event for endtime plugin to hook into
         Event::run('ushahidi_action.report_posted_frontend', $post);
         // Test to see if things passed the rule checks
         if (reports::validate($post)) {
             // STEP 1: SAVE LOCATION
             $location = new Location_Model();
             reports::save_location($post, $location);
             // STEP 2: SAVE INCIDENT
             $incident = new Incident_Model();
             reports::save_report($post, $incident, $location->id);
             // STEP 2b: SAVE INCIDENT GEOMETRIES
             reports::save_report_geometry($post, $incident);
             // STEP 3: SAVE CATEGORIES
             reports::save_category($post, $incident);
             // STEP 4: SAVE MEDIA
             reports::save_media($post, $incident);
             // STEP 5: SAVE CUSTOM FORM FIELDS
             reports::save_custom_fields($post, $incident);
             // STEP 6: SAVE PERSONAL INFORMATION
             reports::save_personal_info($post, $incident);
             // Run events
             Event::run('ushahidi_action.report_submit', $post);
             Event::run('ushahidi_action.report_add', $incident);
             url::redirect('reports/thanks');
         } else {
             // Repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // Populate the error fields, if any
             $errors = arr::merge($errors, $post->errors('report'));
             // JP: Replace default Report Title and Description names with custom names in the error listing.
             if ($errors['incident_title'] and !empty($form['form_data']->report_title_name)) {
                 $errors['incident_title'] = str_replace(Kohana::lang('ui_main.reports_title'), $form['form_data']->report_title_name, $errors['incident_title']);
             }
             if ($errors['incident_description'] and !empty($form['form_data']->description_name)) {
                 $errors['incident_description'] = str_replace(Kohana::lang('ui_main.reports_description'), $form['form_data']->description_name, $errors['incident_description']);
             }
             $form_error = TRUE;
         }
     }
     // Retrieve Country Cities
     $default_country = Kohana::config('settings.default_country');
     $this->template->content->cities = $this->_get_cities($default_country);
     $this->template->content->multi_country = Kohana::config('settings.multi_country');
     $this->template->content->id = $id;
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     // Populate this for backwards compat
     $this->template->content->categories = array();
     // Pass timezone
     $this->template->content->site_timezone = Kohana::config('settings.site_timezone');
     // Pass the submit report message
     $this->template->content->site_submit_report_message = Kohana::config('settings.site_submit_report_message');
     // Retrieve Custom Form Fields Structure
     $this->template->content->custom_forms = new View('reports/submit_custom_forms');
     // JP: This needs to be passed $form['form_id'] rather than $form_id so that we use the correct custom fields.
     $disp_custom_fields = customforms::get_custom_form_fields($id, $form['form_id'], FALSE);
     $this->template->content->disp_custom_fields = $disp_custom_fields;
     $this->template->content->stroke_width_array = $this->_stroke_width_array();
     $this->template->content->custom_forms->disp_custom_fields = $disp_custom_fields;
     $this->template->content->custom_forms->form = $form;
     // Javascript Header
     $this->themes->map_enabled = TRUE;
     $this->themes->treeview_enabled = TRUE;
     $this->themes->colorpicker_enabled = TRUE;
     $this->themes->js = new View('reports/submit_edit_js');
     $this->themes->js->edit_mode = FALSE;
     $this->themes->js->incident_zoom = FALSE;
     $this->themes->js->default_map = Kohana::config('settings.default_map');
     $this->themes->js->default_zoom = Kohana::config('settings.default_zoom');
     if (!$form['latitude'] or !$form['latitude']) {
         $this->themes->js->latitude = Kohana::config('settings.default_lat');
         $this->themes->js->longitude = Kohana::config('settings.default_lon');
     } else {
         $this->themes->js->latitude = $form['latitude'];
         $this->themes->js->longitude = $form['longitude'];
     }
     $this->themes->js->geometries = $form['geometry'];
 }
Example #23
0
 /**
  * This function will append the value to an existing value in an array if
  * one exists at the provided path, otherwise it is added as new.
  *
  * @param array $array
  * @param string $value
  * @param array $paths
  * @return array
  */
 public static function append_array(&$array, $value, $paths)
 {
     if ($existing = self::get_array($array, $paths)) {
         if (is_string($existing)) {
             $value = $existing . self::$append_string_separator . $value;
             $value = trim($value, self::$append_string_separator);
         } else {
             if (is_array($existing)) {
                 $value = arr::merge($existing, (array) $value);
             } else {
                 throw new Exception('Unable to append array values of type ' . gettype($value));
             }
         }
     }
     return self::set_array($array, $value, $paths);
 }
Example #24
0
File: i18n.php Project: swk/bluebox
 /**
  * This method allows bulk merge of option key/values
  */
 public function mergeOptions($options)
 {
     if (is_array($options)) {
         self::$options = arr::merge($options, self::$options);
     }
     // return the instance to allow method chaining
     return self::$instance;
 }
Example #25
0
 public static function associateNumbers(&$base = NULL)
 {
     if (!$base) {
         $base = Event::$data;
     }
     if (empty($_POST['numbers']['assigned'])) {
         return TRUE;
     }
     if (get_parent_class($base) == 'Bluebox_Record') {
         $class_type = get_class($base) . 'Number';
     } else {
         $class_type = get_parent_class($base) . 'Number';
     }
     $identifiers = $base->identifier();
     if (!empty($identifiers)) {
         $foreign_id = reset($identifiers);
     } else {
         $foreign_id = 0;
     }
     foreach ($_POST['numbers']['assigned'] as $number_id => $details) {
         $newNumber = Doctrine::getTable('Number')->find($number_id);
         Kohana::log('debug', 'Associate number ' . $newNumber['number'] . ' (' . $number_id . ') with ' . str_replace('Number', '', $class_type) . ' ' . $foreign_id);
         $newNumber['class_type'] = $class_type;
         $newNumber['foreign_id'] = $foreign_id;
         if (isset($_POST['number' . $number_id]['registry'])) {
             //Kohana::log('debug', 'Updating registry for number ' .$newNumber['number'] .' (' .$number_id .')');
             $newNumber['registry'] = arr::merge($newNumber['registry'], $_POST['number' . $number_id]['registry']);
         }
         if (isset($_POST['number' . $number_id]['dialplan'])) {
             //Kohana::log('debug', 'Updating dialplan for number ' .$newNumber['number'] .' (' .$number_id .')');
             $newNumber['dialplan'] = arr::merge($newNumber['dialplan'], $_POST['number' . $number_id]['dialplan']);
         }
         $newNumber->save();
     }
     return TRUE;
 }
Example #26
0
 private function add_rule($allow, $roles, $resources, $privileges, $assertion)
 {
     // Normalize arguments (build arrays with IDs as string)
     //privileges
     if ($privileges !== NULL and !is_array($privileges)) {
         $privileges = array($privileges);
     }
     //resources
     if ($resources !== NULL) {
         if (!is_array($resources)) {
             $resources = array($resources);
         }
         foreach ($resources as &$resource) {
             if ($resource instanceof Acl_Resource_Interface) {
                 $resource = $resource->get_resource_id();
             } else {
                 $resource = (string) $resource;
             }
         }
     }
     //roles
     if ($roles !== NULL) {
         if (!is_array($roles)) {
             $roles = array($roles);
         }
         foreach ($roles as &$role) {
             if ($role instanceof Acl_Role_Interface) {
                 $role = $role->get_role_id();
             } else {
                 $role = (string) $role;
             }
         }
     }
     // start building rule, from bottom to top
     $rule = array('allow' => $allow, 'assert' => $assertion);
     $rule = $privileges === NULL ? array('allPrivileges' => $rule) : array('byPrivilegeId' => array_fill_keys($privileges, $rule));
     $rule = $roles === NULL ? array('allRoles' => $rule) : array('byRoleId' => array_fill_keys($roles, $rule));
     $rule = $resources === NULL ? array('allResources' => $rule) : array('byResourceId' => array_fill_keys($resources, $rule));
     // using arr::merge, this appends numeric keys, but replaces associative keys
     $this->_rules = arr::merge($this->_rules, $rule);
 }
Example #27
0
 public static function button($href, $title, $options)
 {
     $options = arr::merge($options, array('class' => 'button'));
     return html::anchor($href, $title, $options);
 }
Example #28
0
 public static function catalog($display = NULL)
 {
     $catalog = array();
     $records = Doctrine::getTable(__CLASS__)->findAll();
     $hide_rate = kohana::config('mediafile.hide_rate_folders');
     if (!$display) {
         $display = '%2$s (%4$s %9$shz)';
         if ($hide_rate) {
             $display = '%2$s (%4$s)';
         }
     }
     foreach ($records as $record) {
         $param_arr = arr::merge(array($display), $record);
         $param_arr = array_values($param_arr);
         $catalog[$record->filepath(TRUE, !$hide_rate)] = call_user_func_array('sprintf', $param_arr);
     }
     return $catalog;
 }
 public function __construct($config = null)
 {
     $this->config = arr::merge(Kohana::$config->load('migrations')->as_array(), (array) $config);
     $this->driver(Migration_Driver::factory(Arr::get($this->config, 'database', 'default')));
 }
Example #30
0
 /**
  * This function sorts the columns of a grid by an optional columnWeight parameter
  *
  * @return void
  */
 private function _orderColumns()
 {
     // Sort the columns array
     ksort($this->query['columns'], SORT_NUMERIC);
     // Move the inner arrays (now sorted by the outer array values) to the outer array
     // and ditch the subarray groups of columns by weight
     foreach ($this->query['columns'] as $key => $columns) {
         // FIRST remove the old column (foreach is operating on a copy so it is saving the value)
         unset($this->query['columns'][$key]);
         // Move this inner array to the the outer column array
         $this->query['columns'] = arr::merge($this->query['columns'], $columns);
         // We also need the jquery colModel to reflect the same order so first get the colModel value
         $colModel = $this->jquery['colModel'][$key];
         // Unset the inner array
         unset($this->jquery['colModel'][$key]);
         // Set the outer array with what used to to be the inner array
         $this->jquery['colModel'] = arr::merge($this->jquery['colModel'], $colModel);
     }
     // This is an easy way to re-index the array (otherwise the grid create JS will be incorrect)
     $this->jquery['colModel'] = array_values($this->jquery['colModel']);
 }