示例#1
0
 function index()
 {
     $this->template->content = new View('admin/themes');
     $this->template->content->title = 'Addons';
     // setup and initialize form field names
     $form = array('site_style' => '');
     //  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 = 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 = new Validation($_POST);
         // Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('site_style', 'length[1,50]');
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // Yes! everything is valid
             $settings = new Settings_Model(1);
             $settings->site_style = $post->site_style;
             $settings->save();
             //add details to application/config/email.php
             //$this->_add_email_settings($settings);
             // Delete Settings Cache
             $cache = Cache::instance();
             $cache->delete('settings');
             $cache->delete_tag('settings');
             // Everything is A-Okay!
             $form_saved = TRUE;
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('settings'));
             $form_error = TRUE;
         }
     } else {
         // Retrieve Current Settings
         $settings = ORM::factory('settings', 1);
         $form = array('site_style' => $settings->site_style);
     }
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $this->template->content->themes = $this->_get_themes();
 }
示例#2
0
 /**
  * Handles SMS Settings
  */
 function index()
 {
     $this->template->content = new View('admin/facebook');
     $this->template->content->title = Kohana::lang('ui_admin.settings');
     // setup and initialize form field names
     $form = array('facebook_appid' => '', 'facebook_appsecret' => '');
     //	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 = 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 = new Validation($_POST);
         // Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('facebook_appid', 'length[1,150]');
         $post->add_rules('facebook_appsecret', 'length[1,150]');
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // Yes! everything is valid
             $settings = new Settings_Model(1);
             $settings->facebook_appid = $post->facebook_appid;
             $settings->facebook_appsecret = $post->facebook_appsecret;
             $settings->date_modify = date("Y-m-d H:i:s", time());
             $settings->save();
             // Delete Settings Cache
             $this->cache->delete('settings');
             $this->cache->delete_tag('settings');
             // Everything is A-Okay!
             $form_saved = TRUE;
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('settings'));
             $form_error = TRUE;
         }
     } else {
         // Retrieve Current Settings
         $settings = ORM::factory('settings', 1);
         $form = array('facebook_appid' => $settings->facebook_appid, 'facebook_appsecret' => $settings->facebook_appsecret);
     }
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
 }
示例#3
0
 public static function populate_db($db_name, $user, $settings)
 {
     $mhi_db = Kohana::config('database.default');
     $table_prefix = $mhi_db['table_prefix'];
     $mhi_db_name = $mhi_db['connection']['database'];
     // Switch to new DB for a moment
     mysql_query('USE ' . $db_name);
     $db_schema = file_get_contents('sql/ushahidi.sql');
     // If a table prefix is specified, add it to sql
     if ($table_prefix) {
         $find = array('CREATE TABLE IF NOT EXISTS `', 'INSERT INTO `', 'ALTER TABLE `', 'UPDATE `');
         $replace = array('CREATE TABLE IF NOT EXISTS `' . $table_prefix . '_', 'INSERT INTO `' . $table_prefix . '_', 'ALTER TABLE `' . $table_prefix . '_', 'UPDATE `' . $table_prefix . '_');
         $db_schema = str_replace($find, $replace, $db_schema);
     }
     /**
      * split by ; to get the sql statement for creating individual
      * tables.
      */
     $tables = explode(';', $db_schema);
     foreach ($tables as $query) {
         $result = mysql_query($query);
     }
     // Set up admin user on new site
     $usr = ORM::factory('user', '1');
     $usr->username = $user['username'];
     $usr->name = $user['name'];
     $usr->password = $user['password'];
     $usr->email = $user['email'];
     $usr->save();
     // Save site settings (name, tagline, etc)
     $setgs = new Settings_Model(1);
     $setgs->site_name = $settings['site_name'];
     $setgs->site_tagline = $settings['site_tagline'];
     $setgs->api_google = Kohana::config('settings.api_google');
     $setgs->date_modify = date("Y-m-d H:i:s", time());
     $setgs->save();
     // Switch back to the appropriate DB
     mysql_query('USE ' . $mhi_db_name);
     return true;
 }
示例#4
0
 /**
  * Email Settings
  */
 function email()
 {
     $this->template->content = new View('admin/email');
     $this->template->content->title = Kohana::lang('ui_admin.settings');
     // setup and initialize form field names
     $form = array('email_username' => '', 'email_password' => '', 'email_port' => '', 'email_host' => '', 'email_servertype' => '', 'email_ssl' => '');
     //  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 = 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 = new Validation($_POST);
         // Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('email_username', 'required', 'length[3,50]');
         $post->add_rules('email_password', 'length[3,100]');
         $post->add_rules('email_port', 'numeric[1,100]', 'length[1,20]');
         $post->add_rules('email_host', 'required', 'length[3,100]');
         $post->add_rules('email_servertype', 'required', 'length[3,100]');
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // Yes! everything is valid
             $settings = new Settings_Model(1);
             $settings->email_username = $post->email_username;
             $settings->email_password = $post->email_password;
             $settings->email_port = $post->email_port;
             $settings->email_host = $post->email_host;
             $settings->email_servertype = $post->email_servertype;
             $settings->email_ssl = $post->email_ssl;
             $settings->save();
             //add details to application/config/email.php
             //$this->_add_email_settings($settings);
             // Delete Settings Cache
             $this->cache->delete('settings');
             $this->cache->delete_tag('settings');
             // Everything is A-Okay!
             $form_saved = TRUE;
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('settings'));
             $form_error = TRUE;
         }
     } else {
         // Retrieve Current Settings
         $settings = ORM::factory('settings', 1);
         $form = array('email_username' => $settings->email_username, 'email_password' => $settings->email_password, 'email_port' => $settings->email_port, 'email_host' => $settings->email_host, 'email_servertype' => $settings->email_servertype, 'email_ssl' => $settings->email_ssl);
     }
     $this->template->colorpicker_enabled = TRUE;
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $this->template->content->email_ssl_array = array('1' => Kohana::lang('ui_admin.yes'), '0' => Kohana::lang('ui_admin.no'));
     // Javascript Header
     $this->template->js = new View('admin/email_js');
 }
示例#5
0
 /**
  * Handles settings for Global SMS Providers - Clickatell In This Case
  */
 function smsglobal()
 {
     $this->template->content = new View('admin/smsglobal');
     $this->template->content->title = 'Settings';
     // setup and initialize form field names
     $form = array('clickatell_api' => '', 'clickatell_username' => '', 'clickatell_password' => '');
     //  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 = 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 = new Validation($_POST);
         // Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('clickatell_api', 'required', 'length[4,20]');
         $post->add_rules('clickatell_username', 'required', 'length[3,50]');
         $post->add_rules('clickatell_password', 'required', 'length[5,50]');
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // Yes! everything is valid
             $settings = new Settings_Model(1);
             $settings->clickatell_api = $post->clickatell_api;
             $settings->clickatell_username = $post->clickatell_username;
             $settings->clickatell_password = $post->clickatell_password;
             $settings->date_modify = date("Y-m-d H:i:s", time());
             $settings->save();
             // Everything is A-Okay!
             $form_saved = TRUE;
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('settings'));
             $form_error = TRUE;
         }
     } else {
         // Retrieve Current Settings
         $settings = ORM::factory('settings', 1);
         $form = array('clickatell_api' => $settings->clickatell_api, 'clickatell_username' => $settings->clickatell_username, 'clickatell_password' => $settings->clickatell_password);
     }
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     // Javascript Header
     $this->template->js = new View('admin/smsglobal_js');
 }
示例#6
0
 /**
  * MHI Settings.
  * @param int $page
  */
 function settings()
 {
     $this->template->content = new View('admin/mhi_settings');
     // setup and initialize form field names
     $this->template->content->form = array('google_analytics' => '');
     //  Copy the form as errors, so the errors will be stored with keys
     //  corresponding to the form field names
     $this->template->content->errors = $this->template->content->form;
     $this->template->content->form_error = FALSE;
     $this->template->content->form_saved = 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 = new Validation($_POST);
         // Add some filters
         $post->pre_filter('trim', TRUE);
         // Validation Rules
         $post->add_rules('google_analytics', 'length[0,20]');
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // Yes! everything is valid
             $settings = new Settings_Model(1);
             $settings->google_analytics = $post->google_analytics;
             $settings->date_modify = date("Y-m-d H:i:s", time());
             $settings->save();
             $this->template->content->form_saved = TRUE;
             $this->template->content->form = arr::overwrite($this->template->content->form, $post->as_array());
         } else {
             // repopulate the form fields
             $this->template->content->form = arr::overwrite($this->template->content->form, $post->as_array());
             // populate the error fields, if any
             $this->template->content->errors = arr::overwrite($this->template->content->errors, $post->errors('settings'));
             $this->template->content->form_error = TRUE;
         }
     } else {
         // Retrieve Current Settings
         $settings = ORM::factory('settings', 1);
         $this->template->content->form = array('google_analytics' => $settings->google_analytics);
     }
 }
示例#7
0
 public function index($feedtype = 'rss2')
 {
     $this->template->this_page = 'feed_add';
     $this->template->content = new View('admin/feeds');
     // setup and initialize form field names
     /*	$cat1fields1 = array('1feed_url1' => '',
     												'1weight1' => 1,
     												'1feed_category1' => 1);		
     
     		*/
     $form = array();
     $num_of_fields_persection = 6;
     /** #########  Apala required changes ##########
     		settings should come for api the line below	*/
     $settings = ORM::factory('settings', 1);
     $form["EMAIL"] = $settings->site_email;
     $form["SMS"] = $settings->sms_no1;
     $hashtags = explode(',', $settings->twitter_hashtags);
     $cat_counter = 0;
     $cat_max = count($hashtags);
     for ($i = 1; $i <= $num_of_fields_persection; $i++) {
         if ($cat_counter < $cat_max) {
             $form["hashtag" . $i] = $hashtags[$cat_counter];
             $cat_counter++;
         } else {
             $form["hashtag" . $i] = "";
         }
     }
     /** #########  Apala required changes ##########	
     		These categories and feeds tables should get info from API line 74 and 78.
     */
     $categories = ORM::factory('category')->where('category_visible = 1')->orderby('id')->find_all();
     $coreFolder = DOCROOT . "/../Core/";
     $coreSetupFile = $coreFolder . "Setup.php";
     include_once $coreSetupFile;
     $workflow = new \Swiftriver\Core\Workflows\ChannelProcessingJobs\ListAllChannelProcessingJobs();
     $json = $workflow->RunWorkflow("swiftriver_apala");
     $return = json_decode($json);
     $channels = $return->channels;
     /* APALA - Dropped in favor of the file call
                     $service = new ServiceWrapper($this->API_URL."ListAllChannelProcessingJobs.php");
                     $json = $service->MakePOSTRequest(array("key" => "test"), 5);
                     $return = json_decode($json);
                     $channels = $return->channels;
     		*/
     foreach ($categories as $cat) {
         /** #########  Apala required changes ########## DB Call below. ::factory('feed')*/
         $prev_feeds = $channels;
         //ORM::factory('feed')->where('category_id',$cat->id)->find_all();
         $cat_counter = 0;
         $cat_max = count($prev_feeds);
         for ($i = 1; $i <= $num_of_fields_persection; $i++) {
             //this section gets the information from the database and sign it to the right fields.
             if ($cat_counter < $cat_max && $cat->id == 5) {
                 //|| $cat->id == 4 || $cat->id == 3 ) //only the feed catagories can be saved at a moment.
                 $pre_feed = $prev_feeds[$cat_counter];
                 $form[$cat->category_title . "ID" . $i] = $pre_feed->id;
                 //$pre_feed->id;
                 $form[$cat->category_title . "feed_url" . $i] = $pre_feed->parameters->feedUrl;
                 $form[$cat->category_title . "updatePeriod" . $i] = $pre_feed->updatePeriod;
                 $form[$cat->category_title . "weight" . $i] = 0;
                 //$pre_feed->weight ;
                 $form[$cat->category_title . "feed_category" . $i] = 5;
                 //$pre_feed->category_id;
                 $cat_counter++;
             } else {
                 $form[$cat->category_title . "ID" . $i] = 0;
                 $form[$cat->category_title . "feed_url" . $i] = '';
                 $form[$cat->category_title . "weight" . $i] = 0;
                 $form[$cat->category_title . "updatePeriod" . $i] = 1;
                 $form[$cat->category_title . "feed_category" . $i] = $cat->id;
             }
         }
     }
     /*	echo "<p>";
     		print_r($form);
     		echo "</p>";
     		exit(0);
     		*/
     //copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $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 = Validation::factory(array_merge($_POST, $_FILES));
         //  Add some filters
         $post->pre_filter('trim', TRUE);
         if ($post->validate()) {
             foreach ($categories as $cat) {
                 for ($i = 1; $i <= $num_of_fields_persection; $i++) {
                     if ($cat->id == 5) {
                         if (isset($_POST[$cat->category_title . "feed_url" . $i]) && !empty($_POST[$cat->category_title . "feed_url" . $i])) {
                             $feed_url = $_POST[$cat->category_title . "feed_url" . $i];
                             $feed_weight = $_POST[$cat->category_title . "weight_hf" . $i];
                             $this->_save_feed($feed_url, $cat->id, $_POST[$cat->category_title . "updatePeriod" . $i], isset($_POST[$cat->category_title . "weight" . $i]) ? 100 : ($feed_weight == 100 ? 0 : $feed_weight));
                         } else {
                             if (isset($_POST[$cat->category_title . "ID" . $i]) && $_POST[$cat->category_title . "ID" . $i] != 0) {
                                 // delete what the user has deleted.
                                 $db = new Database();
                                 $db->query("Delete from feed where id=" . $_POST[$cat->category_title . "ID" . $i]);
                             }
                         }
                     }
                 }
             }
             //	exit(0);
             $hashtags = isset($_POST["hashtag1"]) && !empty($_POST["hashtag1"]) ? $_POST["hashtag1"] : '';
             for ($i = 2; $i < $num_of_fields_persection; $i++) {
                 if (isset($_POST["hashtag" . $i]) && !empty($_POST["hashtag" . $i])) {
                     $hashtags .= "," . $_POST["hashtag" . $i];
                 }
             }
             /** #########  Apala required changes ##########
             		settings should come for api the lines below	*/
             //save the hashtags in the settings table.
             /** #########  Apala required changes ########## DB Call below new Settings_Model */
             $settings = new Settings_Model(1);
             $settings->twitter_hashtags = $hashtags;
             $settings->site_email = $_POST["EMAIL"];
             $settings->sms_no1 = $_POST["SMS"];
             $settings->save();
             $this->template->content->form_saved = true;
             $this->template->content->form_action = "Added / Updated";
             //	exit(0);
             url::redirect("/admin/feeds");
         } else {
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('report'));
             $form_error = TRUE;
         }
     }
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = false;
     $this->template->content->form = $form;
     // Count categories to determine column length
 }
示例#8
0
 public function index($feedtype = 'rss2')
 {
     $this->template->this_page = 'feed_add';
     $this->template->content = new View('admin/feeds');
     // setup and initialize form field names
     /*	$cat1fields1 = array('1feed_url1' => '',
     												'1weight1' => 1,
     												'1feed_category1' => 1);		
     
     		*/
     $form = array();
     $num_of_fields_persection = 6;
     $settings = ORM::factory('settings', 1);
     $form["EMAIL"] = $settings->site_email;
     $form["SMS"] = $settings->sms_no1;
     $hashtags = explode(',', $settings->twitter_hashtags);
     $cat_counter = 0;
     $cat_max = count($hashtags);
     for ($i = 1; $i <= $num_of_fields_persection; $i++) {
         if ($cat_counter < $cat_max) {
             $form["hashtag" . $i] = $hashtags[$cat_counter];
             $cat_counter++;
         } else {
             $form["hashtag" . $i] = "";
         }
     }
     $categories = ORM::factory('category')->where('category_visible = 1')->orderby('id')->find_all();
     foreach ($categories as $cat) {
         $prev_feeds = ORM::factory('feed')->where('category_id', $cat->id)->find_all();
         $cat_counter = 0;
         $cat_max = count($prev_feeds);
         for ($i = 1; $i <= $num_of_fields_persection; $i++) {
             //this section gets the information from the database and sign it to the right fields.
             if ($cat_counter < $cat_max && $prev_feeds[$cat_counter]->category_id == $cat->id) {
                 $pre_feed = $prev_feeds[$cat_counter];
                 $form[$cat->category_title . "ID" . $i] = $pre_feed->id;
                 $form[$cat->category_title . "feed_url" . $i] = $pre_feed->feed_url;
                 $form[$cat->category_title . "weight" . $i] = $pre_feed->weight;
                 $form[$cat->category_title . "feed_category" . $i] = $pre_feed->category_id;
                 $cat_counter++;
             } else {
                 $form[$cat->category_title . "ID" . $i] = 0;
                 $form[$cat->category_title . "feed_url" . $i] = '';
                 $form[$cat->category_title . "weight" . $i] = 0;
                 $form[$cat->category_title . "feed_category" . $i] = $cat->id;
             }
         }
     }
     //copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $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 = Validation::factory(array_merge($_POST, $_FILES));
         //  Add some filters
         $post->pre_filter('trim', TRUE);
         if ($post->validate()) {
             foreach ($categories as $cat) {
                 for ($i = 1; $i <= $num_of_fields_persection; $i++) {
                     if (isset($_POST[$cat->category_title . "feed_url" . $i]) && !empty($_POST[$cat->category_title . "feed_url" . $i])) {
                         $feed_url = $_POST[$cat->category_title . "feed_url" . $i];
                         $feed_weight = $_POST[$cat->category_title . "weight_hf" . $i];
                         $this->_save_feed($_POST[$cat->category_title . "ID" . $i], $feed_url, $cat->id, $feed_url, isset($_POST[$cat->category_title . "weight" . $i]) ? 100 : ($feed_weight == 100 ? 0 : $feed_weight));
                     } else {
                         if (isset($_POST[$cat->category_title . "ID" . $i]) && $_POST[$cat->category_title . "ID" . $i] != 0) {
                             // delete what the user has deleted.
                             $db = new Database();
                             $db->query("Delete from feed where id=" . $_POST[$cat->category_title . "ID" . $i]);
                         }
                     }
                 }
             }
             //	exit(0);
             $hashtags = isset($_POST["hashtag1"]) && !empty($_POST["hashtag1"]) ? $_POST["hashtag1"] : '';
             for ($i = 2; $i < $num_of_fields_persection; $i++) {
                 if (isset($_POST["hashtag" . $i]) && !empty($_POST["hashtag" . $i])) {
                     $hashtags .= "," . $_POST["hashtag" . $i];
                 }
             }
             //save the hashtags in the settings table.
             $settings = new Settings_Model(1);
             $settings->twitter_hashtags = $hashtags;
             $settings->site_email = $_POST["EMAIL"];
             $settings->sms_no1 = $_POST["SMS"];
             $settings->save();
             $this->template->content->form_saved = true;
             $this->template->content->form_action = "Added / Updated";
             //	exit(0);
             url::redirect("/admin/feeds");
         } else {
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('report'));
             $form_error = TRUE;
         }
     }
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = false;
     $this->template->content->form = $form;
     // Count categories to determine column length
 }