<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>application/controllers/admin/feedback.php</filename>
    </added>
    <added>
      <filename>application/views/admin/feedback.php</filename>
    </added>
    <added>
      <filename>application/views/admin/form_utils_js.php</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -6,85 +6,84 @@
  * LICENSE: This source file is subject to LGPL license 
  * that is available through the world-wide-web at the following URI:
  * http://www.gnu.org/copyleft/lesser.html
- * @author     Ushahidi Team &lt;team@ushahidi.com&gt; 
+ * @author	   Ushahidi Team &lt;team@ushahidi.com&gt; 
  * @package    Ushahidi - http://source.ushahididev.com
- * @module     Admin Controller  
+ * @module	   Admin Controller  
  * @copyright  Ushahidi - http://www.ushahidi.com
  * @license    http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL) 
  */
 
-class Admin_Controller extends Template_Controller {
-
-    public $auto_render = TRUE;
+class Admin_Controller extends Template_Controller
+{
+	public $auto_render = TRUE;
 	
-    // Main template
-    public $template = 'admin/layout';
+	// Main template
+	public $template = 'admin/layout';
 	
-    // Cache instance
-    protected $cache;
+	// Cache instance
+	protected $cache;
 
-    // Enable auth
-    protected $auth_required = FALSE;
+	// Enable auth
+	protected $auth_required = FALSE;
 	
-    protected $user;
-
+	protected $user;
 
-    public function __construct()
-    {
-        parent::__construct();	
+	public function __construct()
+	{
+		parent::__construct();	
 
-        // Load cache
-        $this-&gt;cache = new Cache;
+		// Load cache
+		$this-&gt;cache = new Cache;
 
-        // Load session
-        $this-&gt;session = new Session;
+		// Load session
+		$this-&gt;session = new Session;
 
-        // Load database
-        $this-&gt;db = new Database();
+		// Load database
+		$this-&gt;db = new Database();
 		
-        $this-&gt;auth = new Auth();
-        $this-&gt;session = Session::instance();
-        $this-&gt;auth-&gt;auto_login();
-        if (!$this-&gt;auth-&gt;logged_in('admin')
-             &amp;&amp; !$this-&gt;auth-&gt;logged_in('login'))
-        {
-            url::redirect('login');
-        }
+		$this-&gt;auth = new Auth();
+		$this-&gt;session = Session::instance();
+		$this-&gt;auth-&gt;auto_login();
 		
+		if (!$this-&gt;auth-&gt;logged_in('admin')
+			 &amp;&amp; !$this-&gt;auth-&gt;logged_in('login'))
+		{
+			url::redirect('login');
+		}
 		
-        // Get Session Information
-        $user = new User_Model($_SESSION['auth_user']-&gt;id);
+		// Get Session Information
+		$user = new User_Model($_SESSION['auth_user']-&gt;id);
 		
-        $this-&gt;template-&gt;admin_name = $user-&gt;name;
+		$this-&gt;template-&gt;admin_name = $user-&gt;name;
 		
-        // Retrieve Default Settings
-        $this-&gt;template-&gt;site_name = Kohana::config('settings.site_name');
-        $this-&gt;template-&gt;mapstraction = Kohana::config('settings.mapstraction');
-        $this-&gt;template-&gt;api_url = Kohana::config('settings.api_url');
+		// Retrieve Default Settings
+		$this-&gt;template-&gt;site_name = Kohana::config('settings.site_name');
+		$this-&gt;template-&gt;mapstraction = Kohana::config('settings.mapstraction');
+		$this-&gt;template-&gt;api_url = Kohana::config('settings.api_url');
 		
-        // Javascript Header
-        $this-&gt;template-&gt;map_enabled = FALSE;
+		// Javascript Header
+		$this-&gt;template-&gt;map_enabled = FALSE;
 		$this-&gt;template-&gt;flot_enabled = FALSE;
-        $this-&gt;template-&gt;colorpicker_enabled = FALSE;
-        $this-&gt;template-&gt;js = '';
+		$this-&gt;template-&gt;colorpicker_enabled = FALSE;
+		$this-&gt;template-&gt;js = '';
 		
-        // Load profiler
-        // $profiler = new Profiler;		
+		// Load profiler
+		// $profiler = new Profiler;		
 		
-    }
+	}
 
-    public function index()
-    {
-        // Send them to the right page
-        url::redirect('admin/dashboard');
-    }
+	public function index()
+	{
+		// Send them to the right page
+		url::redirect('admin/dashboard');
+	}
 
-    public function log_out()
-    {
-        $auth = new Auth;
-        $auth-&gt;logout(TRUE);
+	public function log_out()
+	{
+		$auth = new Auth;
+		$auth-&gt;logout(TRUE);
 
-        url::redirect('login');
-    }		
+		url::redirect('login');
+	}		
 
 } // End Admin</diff>
      <filename>application/controllers/admin.php</filename>
    </modified>
    <modified>
      <diff>@@ -183,4 +183,4 @@ class Comments_Controller extends Admin_Controller
 		$this-&gt;template-&gt;js = new View('admin/comments_js');		
 	}
 	
-}
\ No newline at end of file
+}</diff>
      <filename>application/controllers/admin/comments.php</filename>
    </modified>
    <modified>
      <diff>@@ -36,8 +36,16 @@ class Messages_Controller extends Admin_Controller
 		$this-&gt;template-&gt;content-&gt;title = $service-&gt;service_name;
 
         //So far this assumes that selected 'message_id's are for deleting
-        if (isset($_POST['message_id']))
-            $this-&gt;deleteMessages($_POST['message_id']);
+		if (isset($_POST['message_id']))
+		{
+			if ($_POST['action'] == 'rank') 
+			{
+				$this-&gt;rankMessages($_POST['message_id'], $_POST['level']);
+			} else 
+			{	
+				$this-&gt;deleteMessages($_POST['message_id']);
+			}
+		}
 
 		// Is this an Inbox or Outbox Filter?
 		if (!empty($_GET['type']))
@@ -59,12 +67,38 @@ class Messages_Controller extends Admin_Controller
 			$type = &quot;1&quot;;
 			$filter = 'message_type = 1';
 		}
+		
+		// Any time period filter?
+		$period = 'a';
+		if (!empty($_GET['period']))
+		{
+			$period = $_GET['period'];
+			
+			if ($period == 'd')
+			{
+				$message_date = date(&quot;Y-m-d 00:00:00&quot;, mktime(0, 0, 0,date(&quot;m&quot;),date(&quot;d&quot;)-1,date(&quot;Y&quot;)));
+				$end_date = date(&quot;Y-m-d 00:00:00&quot;, mktime(0, 0, 0, date(&quot;m&quot;), date(&quot;d&quot;), date(&quot;Y&quot;)));
+			} elseif ($period == 'm')
+			{
+				$message_date = date(&quot;Y-m-01 00:00:00&quot;, mktime(0, 0, 0, date(&quot;m&quot;)-1, date(&quot;d&quot;), date(&quot;Y&quot;)));
+				$end_date = date(&quot;Y-m-01 00:00:00&quot;, mktime(0, 0, 0, date(&quot;m&quot;), date(&quot;d&quot;), date(&quot;Y&quot;)));
+			} elseif ($period == 'y')
+			{
+				$message_date = date(&quot;Y-01-01 00:00:00&quot;, mktime(0, 0, 0, date(&quot;m&quot;), date(&quot;d&quot;), date(&quot;Y&quot;)-1));
+				$end_date = date(&quot;Y-01-01 00:00:00&quot;, mktime(0, 0, 0, date(&quot;m&quot;), date(&quot;d&quot;), date(&quot;Y&quot;)));
+			}
+			
+			if (isset($message_date))
+			{
+				$filter .= &quot; AND message_date &gt;= '&quot; . $message_date . &quot;' AND message_date &lt; '&quot; . $end_date .&quot;'&quot;;
+			}
+		}
 
 		// check, has the form been submitted?
 		$form_error = FALSE;
 		$form_saved = FALSE;
 		$form_action = &quot;&quot;;
-
+		
 		// Pagination
 		$pagination = new Pagination(array(
 			'query_string'   =&gt; 'page',
@@ -90,13 +124,17 @@ class Messages_Controller extends Admin_Controller
 		$this-&gt;template-&gt;content-&gt;form_error = $form_error;
 		$this-&gt;template-&gt;content-&gt;form_saved = $form_saved;
 		$this-&gt;template-&gt;content-&gt;form_action = $form_action;
+		
+		$levels = ORM::factory('level')-&gt;orderby('level_weight')-&gt;find_all();
+		$this-&gt;template-&gt;content-&gt;levels = $levels;
 
 		// Total Reports
 		$this-&gt;template-&gt;content-&gt;total_items = $pagination-&gt;total_items;
 
 		// Message Type Tab - Inbox/Outbox
 		$this-&gt;template-&gt;content-&gt;type = $type;
-
+		$this-&gt;template-&gt;content-&gt;period = $period;
+		
 		// Javascript Header
 		$this-&gt;template-&gt;js = new View('admin/messages_js');
 	}
@@ -280,6 +318,23 @@ class Messages_Controller extends Admin_Controller
     }
 
     /**
+     * Rank selected messages
+     */
+    function rankMessages($ids,$level,$dbtable='message')
+    {
+        //XXX:get the current page number
+    	foreach($ids as $id)
+        {
+            $msg = ORM::factory($dbtable)-&gt;find($id);
+            $msg-&gt;message_level = $level;
+            $msg-&gt;save();
+        }
+    	$extradir = '';
+        // url::redirect('admin/messages/'.$extradir);
+
+    }
+
+    /**
 	* Lists the Twitter messages.
     */
 	function twitter()</diff>
      <filename>application/controllers/admin/messages.php</filename>
    </modified>
    <modified>
      <diff>@@ -13,14 +13,11 @@
  * @license    http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL) 
  */
 
-class Alerts_Controller extends Main_Controller {
-
+class Alerts_Controller extends Main_Controller 
+{
     const MOBILE_ALERT = 1;
 	const EMAIL_ALERT = 2;
 	
-    const CODE_LENGTH = 6;
-	private $code_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
-	
 	function __construct()
     {
         parent::__construct();
@@ -44,17 +41,17 @@ class Alerts_Controller extends Main_Controller {
         // Retrieve Country Cities
         $this-&gt;template-&gt;content-&gt;cities = $this-&gt;_get_cities($default_country);
 		
-	// setup and initialize form field names
+		// Setup and initialize form field names
         $form = array (
-                'alert_mobile'      =&gt; '',
-                'alert_mobile_yes'      =&gt; '',
-                'alert_email'      =&gt; '',
-                'alert_email_yes'      =&gt; '',
-                'alert_lat'    =&gt; '',
-                'alert_lon'  =&gt; ''
-             );
+                'alert_mobile' =&gt; '',
+                'alert_mobile_yes' =&gt; '',
+                'alert_email' =&gt; '',
+                'alert_email_yes' =&gt; '',
+                'alert_lat' =&gt; '',
+                'alert_lon' =&gt; ''
+        	);
 
-        // copy the form as errors, so the errors will be stored with keys
+        // Copy the form as errors, so the errors will be stored with keys
         // corresponding to the form field names
         $errors = $form;
         $form_error = FALSE;
@@ -63,31 +60,36 @@ class Alerts_Controller extends Main_Controller {
         // 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
+            // Instantiate Validation, use $post, so we don't overwrite 
+			// $_POST fields with our own things
             $post = new Validation($_POST);
 
             //  Add some filters
             $post-&gt;pre_filter('trim', TRUE);
 			
-            // Add some rules, the input field, followed by a list of checks, carried out in order
-            if ( !empty($_POST['alert_mobile']) || isset($_POST['alert_mobile_yes']) )
+            // Add some rules, the input field, followed by a list of checks, 
+			// carried out in order
+            if (!empty($_POST['alert_mobile']) || isset($_POST['alert_mobile_yes']))
             {
                 $post-&gt;add_rules('alert_mobile', 'required', 'numeric', 'length[6,20]');
             }
 			
-            if ( !empty($_POST['alert_email']) || isset($_POST['alert_email_yes']) )
+            if (!empty($_POST['alert_email']) || isset($_POST['alert_email_yes']))
             {
                 $post-&gt;add_rules('alert_email', 'required', 'email', 'length[3,64]');
             }
 			
-            if ( empty($_POST['alert_email']) &amp;&amp; empty($_POST['alert_mobile']) )
+            if (empty($_POST['alert_email']) &amp;&amp; empty($_POST['alert_mobile']))
             {
-                $post-&gt;add_error('alert_mobile','one_required');
-                $post-&gt;add_error('alert_email','one_required');
+                $post-&gt;add_error('alert_mobile', 'one_required');
+                $post-&gt;add_error('alert_email', 'one_required');
             }
 			
-            $post-&gt;add_rules('alert_lat','required','between[-90,90]'); // Validate for maximum and minimum latitude values
-            $post-&gt;add_rules('alert_lon','required','between[-180,180]'); // Validate for maximum and minimum longitude values
+			// Validate for maximum and minimum latitude values
+            $post-&gt;add_rules('alert_lat', 'required', 'between[-90,90]'); 
+            
+			// Validate for maximum and minimum longitude values
+			$post-&gt;add_rules('alert_lon', 'required', 'between[-180,180]'); 
 			
             // Add a callback, to validate the mobile phone/email (See the methods below)
             $post-&gt;add_callbacks('alert_mobile', array($this, 'mobile_check'));
@@ -104,74 +106,16 @@ class Alerts_Controller extends Main_Controller {
 
 				if (!empty($post-&gt;alert_mobile))
 				{
-                    $alert_code = $this-&gt;_mk_code();
-					
-					$settings = ORM::factory('settings', 1);
-					if ($settings-&gt;loaded == true) 
-					{
-                        // Get SMS Numbers
-                        if (!empty($settings-&gt;sms_no3)) {
-                            $sms_from = $settings-&gt;sms_no3;
-                        }elseif (!empty($settings-&gt;sms_no2)) {
-                            $sms_from = $settings-&gt;sms_no2;
-                        }elseif (!empty($settings-&gt;sms_no1)) {
-                            $sms_from = $settings-&gt;sms_no1;
-                        }else{
-                            $sms_from = &quot;000&quot;;// User needs to set up an SMS number
-                        }
-
-						$sms = new Clickatell();
-						$sms-&gt;api_id = $settings-&gt;clickatell_api;
-						$sms-&gt;user = $settings-&gt;clickatell_username;
-						$sms-&gt;password = $settings-&gt;clickatell_password;
-						$sms-&gt;use_ssl = false;
-						$sms-&gt;sms();
-						$message = &quot;Your alerts confirmation code
-								is: &quot;.$alert_code.&quot; This code is NOT case sensitive&quot;;
-                    
-						if ($sms-&gt;send ($post-&gt;alert_mobile, $sms_from, $message) == &quot;OK&quot;)
-						{
-							$alert = ORM::factory('alert');
-							$alert-&gt;alert_type = self::MOBILE_ALERT;
-							$alert-&gt;alert_recipient = $post-&gt;alert_mobile;
-							$alert-&gt;alert_code = $alert_code;
-							$alert-&gt;alert_lon = $post-&gt;alert_lon;
-							$alert-&gt;alert_lat = $post-&gt;alert_lat;
-							$alert-&gt;save();
-						
-							if ($alert-&gt;saved == TRUE)
-								$sms_confirmation_saved = TRUE;
-						}
-					}
+        			$sms_confirmation_saved =
+						$this-&gt;_send_mobile_alert($post-&gt;alert_mobile,
+								$post-&gt;alert_lon, $post-&gt;alert_lat);
 				}
 
 				if (!empty($post-&gt;alert_email))
 				{
-					$alert_code = $this-&gt;_mk_code();
-					
-					//Send verification email
-                    $config = kohana::config('alerts');
-                    $settings = kohana::config('settings');
-					
-                    $to = $post-&gt;alert_email;
-					$from = $config['alerts_email'];
-					$subject = $settings['site_name'].' alerts - verification';
-					$message = 'Please follow '.url::site().'alerts/verify/'.$alert_code.
-                               ' to confirm your alert request';
-
-					if (email::send($to, $from, $subject, $message, TRUE) == 1)
-					{
-						$alert = ORM::factory('alert');
-						$alert-&gt;alert_type = self::EMAIL_ALERT;
-						$alert-&gt;alert_recipient = $post-&gt;alert_email;
-						$alert-&gt;alert_code = $alert_code;
-						$alert-&gt;alert_lon = $post-&gt;alert_lon;
-						$alert-&gt;alert_lat = $post-&gt;alert_lat;
-						$alert-&gt;save();
-						
-						if ($alert-&gt;saved == TRUE)
-							$email_confirmation_saved = TRUE;
-					}
+					$email_confirmation_saved =
+						$this-&gt;_send_email_alert($post-&gt;alert_email,
+								$post-&gt;alert_lon, $post-&gt;alert_lat);
 				}
 
                 $this-&gt;session-&gt;set('alert_mobile', $post-&gt;alert_mobile);
@@ -180,9 +124,8 @@ class Alerts_Controller extends Main_Controller {
 									$sms_confirmation_saved);
                 $this-&gt;session-&gt;set('email_confirmation_saved',
 									$email_confirmation_saved);
-
-
-                url::redirect('alerts/confirm');					
+                
+				url::redirect('alerts/confirm');					
             }
             // No! We have validation errors, we need to show the form again, with the errors
             else
@@ -220,65 +163,68 @@ class Alerts_Controller extends Main_Controller {
      */
     function confirm ()
     {
-        //$this-&gt;template-&gt;header-&gt;this_page = 'alerts';
         $this-&gt;template-&gt;content = new View('alerts_confirm');
-		if (isset($_SESSION['alert_mobile']) &amp;&amp; isset($_SESSION['alert_email'])) {
+
+		if (isset($_SESSION['alert_mobile']) &amp;&amp; isset($_SESSION['alert_email']))
+		{
 			$this-&gt;template-&gt;content-&gt;alert_mobile = $_SESSION['alert_mobile'];
 			$this-&gt;template-&gt;content-&gt;alert_email = $_SESSION['alert_email'];
 		}
 
 		$this-&gt;template-&gt;content-&gt;email_confirmation_saved =
-			isset($_SESSION['email_confirmation_saved']) ? $_SESSION['email_confirmation_saved'] : FALSE;
+			isset($_SESSION['email_confirmation_saved']) 
+			    ? $_SESSION['email_confirmation_saved'] : FALSE;
 		$this-&gt;template-&gt;content-&gt;sms_confirmation_saved =
-			isset($_SESSION['sms_confirmation_saved']) ? $_SESSION['sms_confirmation_saved'] : FALSE;
-
+			isset($_SESSION['sms_confirmation_saved']) 
+			    ? $_SESSION['sms_confirmation_saved'] : FALSE;
     }
-
+    
+    
     /**
      * Verifies a previously sent alert confirmation code
+     * 
+     * @param string $code
      */
-    function verify($code=NULL)
-    {
-		$errno = NULL;
-		define(&quot;ER_CODE_VERIFIED&quot;, 0);
-		define(&quot;ER_CODE_NOT_FOUND&quot;, 1);
-		define(&quot;ER_CODE_ALREADY_VERIFIED&quot;, 2);
-
-		if (isset($_POST['alert_code']))
-			$code = trim($_POST['alert_code']);
-
-		if ($code != NULL)
-		{
-			$code = ORM::factory('alert')
-					-&gt;where('alert_code', $code)-&gt;find();
-		
-			if (!$code-&gt;id)
-			{
-				$errno = ER_CODE_NOT_FOUND;
-			}
-
-			elseif ($code-&gt;alert_confirmed == 1)
-			{
-				$errno = ER_CODE_ALREADY_VERIFIED; 
-			}
-
-			else
-			{
-				$code-&gt;alert_confirmed = 1;
-				$code-&gt;save($code-&gt;id);
-
-				if ($code-&gt;saved == true)
-					$errno = ER_CODE_VERIFIED;
-			}
-		}
-
-		else
-			$errno = ER_CODE_NOT_FOUND;
-
-		$this-&gt;template-&gt;header-&gt;this_page = 'alerts';
+    public function verify ( )
+    {   // INITIALIZE the content's section of the view
         $this-&gt;template-&gt;content = new View('alerts_verify');
-		$this-&gt;template-&gt;content-&gt;errno = $errno;
-    }
+        $this-&gt;template-&gt;header-&gt;this_page = 'alerts';
+        
+        // IF data has been posted to the request ...
+        if ($post = $this-&gt;input-&gt;post())
+        {   // TRY to update the model and save it
+            try
+            {   // CREATE a local variable representing the alert identified with _POST
+                $Code = ORM::factory('alert', $post['alert_code']);
+                
+                // IF the code couldn't be loaded ...
+                if (! $Code-&gt;loaded)
+                {   // THROW an exception
+                    throw new Kohana_Exception('Code not found');
+                }    
+                
+                if ($Code-&gt;alert_confirmed)
+                {   // SET the errno message to previously confirmed
+                    $this-&gt;template-&gt;content-&gt;errno = Alert_Model::ER_CODE_ALREADY_VERIFIED;
+                }
+                    
+                // SET the alert as confirmed, and save it
+                $Code-&gt;set('alert_confirmed', 1)-&gt;save();
+            }
+            // CATCH any exceptions that might occur ...
+            catch (Exception $e)
+            {   // SET the errno var to not found, indicating the likley error
+                $this-&gt;template-&gt;content-&gt;errno = Alert_Model::ER_CODE_NOT_FOUND;
+            }
+        }
+        // ELSE, no data was posted to the request ...
+        else
+        {   // SET the errno var to not found, indicating the likley error
+            $this-&gt;template-&gt;content-&gt;errno = Alert_Model::ER_CODE_NOT_FOUND;
+        }
+        
+    } // END function ccverify
+    
 	
     /*
      * Retrieves Previously Cached Geonames Cities
@@ -287,8 +233,9 @@ class Alerts_Controller extends Main_Controller {
     {
         $cities = ORM::factory('city')-&gt;orderby('city', 'asc')-&gt;find_all();
         $city_select = array('' =&gt; Kohana::lang('ui_main.alerts_select_city'));
-        foreach ($cities as $city) {
-            $city_select[$city-&gt;city_lon .  &quot;,&quot; . $city-&gt;city_lat] = $city-&gt;city;
+        foreach ($cities as $city) 
+		{
+            $city_select[$city-&gt;city_lon.&quot;,&quot;.$city-&gt;city_lat] = $city-&gt;city;
         }
         return $city_select;
     }
@@ -306,12 +253,13 @@ class Alerts_Controller extends Main_Controller {
 
         // Now check for similar alert in system
         $mobile_check = ORM::factory('alert')
-            -&gt;where('alert_type', self::MOBILE_ALERT)
-            -&gt;where('alert_recipient', $post-&gt;alert_mobile)
-            -&gt;where('alert_lat', $post-&gt;alert_lat)
-            -&gt;where('alert_lon', $post-&gt;alert_lon)-&gt;find();
+            				-&gt;where('alert_type', self::MOBILE_ALERT)
+            				-&gt;where('alert_recipient', $post-&gt;alert_mobile)
+            				-&gt;where('alert_lat', $post-&gt;alert_lat)
+            				-&gt;where('alert_lon', $post-&gt;alert_lon)
+							-&gt;find();
         
-        if ( $mobile_check-&gt;id )
+        if ($mobile_check-&gt;id)
         {
             // Add a validation error, this will cause $post-&gt;validate() to return FALSE
             $post-&gt;add_error( 'alert_mobile', 'mobile_check');
@@ -331,12 +279,13 @@ class Alerts_Controller extends Main_Controller {
 
         // Now check for similar alert in system
         $email_check = ORM::factory('alert')
-            -&gt;where('alert_type', self::EMAIL_ALERT)
-            -&gt;where('alert_recipient', $post-&gt;alert_email)
-            -&gt;where('alert_lat', $post-&gt;alert_lat)
-            -&gt;where('alert_lon', $post-&gt;alert_lon)-&gt;find();
+            			-&gt;where('alert_type', self::EMAIL_ALERT)
+            			-&gt;where('alert_recipient', $post-&gt;alert_email)
+            			-&gt;where('alert_lat', $post-&gt;alert_lat)
+            			-&gt;where('alert_lon', $post-&gt;alert_lon)
+						-&gt;find();
 
-        if ( $email_check-&gt;id )
+        if ($email_check-&gt;id)
         {
             // Add a validation error, this will cause $post-&gt;validate() to return FALSE
             $post-&gt;add_error( 'alert_email', 'email_check');
@@ -348,23 +297,115 @@ class Alerts_Controller extends Main_Controller {
 	 */
 	private function _mk_code()
 	{
-		$max_char_pos = strlen($this-&gt;code_chars)-1;
+		$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
+		$max = strlen($chars)-1;
+		$code_length = 6;
 		$code = NULL;
 
-        for($i = 0; $i &lt; self::CODE_LENGTH; $i++) 
-        {
-			$pos = mt_rand(0, $max_char_pos);
-			$code.=$this-&gt;code_chars[$pos];
+        // Generate unique codes only
+		while(1)
+		{
+			for($i = 0; $i &lt; $code_length; $i++) 
+			{
+				$code.=$chars[mt_rand(0, $max)];
+			}
+
+			$code_check = ORM::factory('alert')
+							-&gt;where('alert_code', $code)-&gt;find();
+
+			if (!$code_check-&gt;id)
+				break;
 		}
 
-        // Only generate unique codes. If a code has been used before, generate
-		// a new one.
-        $code_check = ORM::factory('alert')
-            			-&gt;where('alert_code', $code)-&gt;find();
+		return $code;
+	}
 
-        if (!$code_check-&gt;id)
-			return $code;
-		
-		$this-&gt;_mk_code();
+	private function _send_mobile_alert($alert_mobile, $alert_lon, $alert_lat)
+	{
+        // Instantiate Validation, use $post, so we don't overwrite 
+        // $_POST fields with our own things
+        $post = new Validation($_POST);
+        
+		$alert_code = $this-&gt;_mk_code();
+					
+		$settings = ORM::factory('settings', 1);
+
+		if (!$settings-&gt;loaded)
+			return FALSE;
+
+		// Get SMS Numbers
+		if (!empty($settings-&gt;sms_no3)) 
+		{
+			$sms_from = $settings-&gt;sms_no3;
+		}
+		elseif (!empty($settings-&gt;sms_no2)) 
+		{
+			$sms_from = $settings-&gt;sms_no2;
+		}
+		elseif (!empty($settings-&gt;sms_no1)) 
+		{
+			$sms_from = $settings-&gt;sms_no1;
+		}
+		else
+		{
+			$sms_from = &quot;000&quot;;// User needs to set up an SMS number
+		}
+
+		$sms = new Clickatell();
+		$sms-&gt;api_id = $settings-&gt;clickatell_api;
+		$sms-&gt;user = $settings-&gt;clickatell_username;
+		$sms-&gt;password = $settings-&gt;clickatell_password;
+		$sms-&gt;use_ssl = false;
+		$sms-&gt;sms();
+		$message = &quot;Your alerts confirmation code
+				is: &quot;.$alert_code.&quot; This code is NOT case sensitive&quot;;
+	
+		if ($sms-&gt;send($alert_mobile, $sms_from, $message) == &quot;OK&quot;)
+		{
+			$alert = ORM::factory('alert');
+			$alert-&gt;alert_type = self::MOBILE_ALERT;
+			$alert-&gt;alert_recipient = $alert_mobile;
+			$alert-&gt;alert_code = $alert_code;
+			$alert-&gt;alert_lon = $alert_lon;
+			$alert-&gt;alert_lat = $alert_lat;
+			$alert-&gt;save();
+
+			return TRUE;
+		}
+
+		return FALSE;
 	}
+
+	private function _send_email_alert($alert_email, $alert_lon, $alert_lat)
+	{
+        // Instantiate Validation, use $post, so we don't overwrite 
+        // $_POST fields with our own things
+        $post = new Validation($_POST);
+        
+		$alert_code = $this-&gt;_mk_code();
+		
+		$config = kohana::config('alerts');
+		$settings = kohana::config('settings');
+		
+		$to = $alert_email;
+		$from = $config['alerts_email'];
+		$subject = $settings['site_name'].' alerts - verification';
+		$message = 'Please follow '.url::site().'alerts/verify/'.$alert_code.
+				   ' to confirm your alert request';
+
+		if (email::send($to, $from, $subject, $message, TRUE) == 1)
+		{
+			$alert = ORM::factory('alert');
+			$alert-&gt;alert_type = self::EMAIL_ALERT;
+			$alert-&gt;alert_recipient = $alert_email;
+			$alert-&gt;alert_code = $alert_code;
+			$alert-&gt;alert_lon = $alert_lon;
+			$alert-&gt;alert_lat = $alert_lat;
+			$alert-&gt;save();
+			
+			return TRUE;
+		}
+
+		return FALSE;
+	}	
 }</diff>
      <filename>application/controllers/alerts.php</filename>
    </modified>
    <modified>
      <diff>@@ -27,137 +27,139 @@ class Api_Controller extends Controller {
     function switchTask(){
         $task = &quot;&quot;; //holds the task to perform as requested
         $ret = &quot;&quot;; //return value
-	$request = array();
+		$request = array();
         $error = array();
 		
-	//determine if we are using GET or POST
-	if($_SERVER['REQUEST_METHOD'] == 'GET'){
-	    $request =&amp; $_GET;
-	} else {
-	    $request =&amp; $_POST;
-	}
+		//determine if we are using GET or POST
+		if($_SERVER['REQUEST_METHOD'] == 'GET'){
+	    	$request =&amp; $_GET;
+		} else {
+	    	$request =&amp; $_POST;
+		}
 		
-	//make sure we have a task to work with
-	if(!$this-&gt;_verifyArrayIndex($request, 'task')){
-	    $error = array(&quot;error&quot; =&gt; $this-&gt;_getErrorMsg(001, 'task'));
-	    $task = &quot;&quot;;
-	} else {
-	    $task = $request['task'];
-	}
+		//make sure we have a task to work with
+		if(!$this-&gt;_verifyArrayIndex($request, 'task')){
+	    	$error = array(&quot;error&quot; =&gt; $this-&gt;_getErrorMsg(001, 'task'));
+	    	$task = &quot;&quot;;
+		} else {
+	    	$task = $request['task'];
+		}
 		
-	//response type
-	if(!$this-&gt;_verifyArrayIndex($request, 'resp')){
-	    $this-&gt;responseType = 'json';
+		//response type
+		if(!$this-&gt;_verifyArrayIndex($request, 'resp')){
+	    	$this-&gt;responseType = 'json';
         
         } else {
-	    $this-&gt;responseType = $request['resp'];
-	}
+	    	$this-&gt;responseType = $request['resp'];
+		}
 		
-	switch($task){
-	    case &quot;report&quot;: //report/add an incident
-	        $ret = $this-&gt;_report();
-		break;
-				
-	    case &quot;tagnews&quot;: //tag a news item to an incident
-	    case &quot;tagvideo&quot;: //report/add an incident
-	    case &quot;tagphoto&quot;: //report/add an incident
-	    $incidentid = '';
+		switch($task){
+	    	case &quot;report&quot;: //report/add an incident
+	        	$ret = $this-&gt;_report();
+			break;
 				
-	    if(!$this-&gt;_verifyArrayIndex($request, 'id')){
-	        $error = array(&quot;error&quot; =&gt; $this-&gt;_getErrorMsg(001, 'id'));
-	    } else {
-		break;
-		$incidentid = $request['id'];
-	    }
+	    	case &quot;tagnews&quot;: //tag a news item to an incident
+	    	case &quot;tagvideo&quot;: //report/add an incident
+	    	case &quot;tagphoto&quot;: //report/add an incident
+	    		$incidentid = '';
 				
+	    		if(!$this-&gt;_verifyArrayIndex($request, 'id')) {
+	        		$error = array(&quot;error&quot; =&gt; $this-&gt;_getErrorMsg(001, 'id'));
+					break;
+	    		} else {
+					$incidentid = $request['id'];
+	    		}	
 				
-	    $mediatype = 0;
-	    if($task == &quot;tagnews&quot;)
-	        $mediatype = 4;
+	    		$mediatype = 0;
+	
+	    		if($task == &quot;tagnews&quot;)
+	        		$mediatype = 4;
 					
-	    if($task == &quot;tagvideo&quot;)
-	        $mediatype = 2;
+	    		if($task == &quot;tagvideo&quot;)
+	        		$mediatype = 2;
 					
-	    if($task == &quot;tagphoto&quot;)
-	        $mediatype = 1;
+	    		if($task == &quot;tagphoto&quot;)
+	        		$mediatype = 1;
 					
-	        $ret = $this-&gt;_tagMedia($incidentid, $mediatype);
+	        	$ret = $this-&gt;_tagMedia($incidentid, $mediatype);
 				
-		break;
-		case &quot;apikeys&quot;:
+			break;
+		
+			case &quot;apikeys&quot;:
 			
-			$by = '';
-		   	if(!$this-&gt;_verifyArrayIndex($request, 'by')) {
-				$error = array(&quot;error&quot; =&gt; $this-&gt;_getErrorMsg(001, 'by'));
-				break;
-		   	}else {
-				$by = $request['by'];
-		   	}
+				$by = '';
+		   		if(!$this-&gt;_verifyArrayIndex($request, 'by')) {
+					$error = array(&quot;error&quot; =&gt; $this-&gt;_getErrorMsg(001, 'by'));
+					break;
+		   		}else {
+					$by = $request['by'];
+		   		}
 		    
-			switch($by) {
+				switch($by) {
 				 
-				case &quot;google&quot;:
-					$ret = $this-&gt;_apiKey('api_google');
+					case &quot;google&quot;:
+						$ret = $this-&gt;_apiKey('api_google');
 					
-				break;
+					break;
 
-				case &quot;yahoo&quot;:
-					$ret = $this-&gt;_apiKey('api_yahoo');
-				break;
+					case &quot;yahoo&quot;:
+						$ret = $this-&gt;_apiKey('api_yahoo');
+					break;
 
-				case &quot;microsoft&quot;:
-					$ret = $this-&gt;_apiKey('api_live');
+					case &quot;microsoft&quot;:
+						$ret = $this-&gt;_apiKey('api_live');
 					break;
 					
-				default:
-					$error = array(&quot;error&quot; =&gt;$this-&gt;_getErrorMsg(002));
-			}
-		break;
+					default:
+						$error = array(&quot;error&quot; =&gt;$this-&gt;_getErrorMsg(002));
+				}
+				break;
 					
-	    case &quot;categories&quot;: //retrieve categories
-		$ret = $this-&gt;_categories();
-		break;
+	    	case &quot;categories&quot;: //retrieve categories
+				$ret = $this-&gt;_categories();
+			break;
 				
-	    case &quot;category&quot;: //retrieve categories
-	        $id = 0;
+	    	case &quot;category&quot;: //retrieve categories
+	        	$id = 0;
 				
-	        if(!$this-&gt;_verifyArrayIndex($request, 'id')){
-		    $error = array(&quot;error&quot; =&gt; $this-&gt;_getErrorMsg(001, 'id'));
-		    break;
-		} else {
-		    $id = $request['id'];
-		}
+	        	if(!$this-&gt;_verifyArrayIndex($request, 'id')){
+		    		$error = array(&quot;error&quot; =&gt; $this-&gt;_getErrorMsg(001, 'id'));
+		    		break;
+				} else {
+		    		$id = $request['id'];
+				}
 				
-		$ret = $this-&gt;_category($id);
-		break;
+				$ret = $this-&gt;_category($id);
+				break;
 				
-		case &quot;locations&quot;: //retrieve locations
+			case &quot;locations&quot;: //retrieve locations
 	            $ret = $this-&gt;_locations();
-		    break;		
+		    	break;		
 		
-		case &quot;location&quot;: //retrieve locations
-		    $by = '';
+			case &quot;location&quot;: //retrieve locations
+		    	$by = '';
 				
-	        if(!$this-&gt;_verifyArrayIndex($request, 'by')){
-		    $error = array(&quot;error&quot; =&gt; $this-&gt;_getErrorMsg(001, 'by'));
-		    break;
-		} else {
-		    $by = $request['by'];
-		}
+	        	if(!$this-&gt;_verifyArrayIndex($request, 'by')){
+		    		$error = array(&quot;error&quot; =&gt; $this-&gt;_getErrorMsg(001, 'by'));
+		    		break;
+				} else {
+		    		$by = $request['by'];
+				}
 		
 		
 				
-		switch ($by){
-		    case &quot;latlon&quot;: //latitude and longitude
+				switch ($by){
+		    		case &quot;latlon&quot;: //latitude and longitude
 						//
-		        break;
-		    case &quot;locid&quot;: //id
-		        if(($this-&gt;_verifyArrayIndex($request, 'id'))){
-			    $ret = $this-&gt;_locationById($request['id']);
-			} else {
-			    $error = array(&quot;error&quot; =&gt; $this-&gt;_getErrorMsg(001, 'id'));
-			}
-			break;
+		        	break;
+		    		case &quot;locid&quot;: //id
+		        		if(($this-&gt;_verifyArrayIndex($request, 'id'))){
+			    			$ret = $this-&gt;_locationById($request['id']);
+						} else {
+			    			$error = array(&quot;error&quot; =&gt; $this-&gt;_getErrorMsg(001, 'id'));
+						}
+					break;
+			
 			case &quot;country&quot;: //id
 			    if(($this-&gt;_verifyArrayIndex($request, 'id'))){
 			        $ret = $this-&gt;_locationByCountryId($request['id']);
@@ -263,12 +265,12 @@ class Api_Controller extends Controller {
 			    break;
 			    case &quot;latlon&quot;: //latitude and longitude
                                 
-                                if(($this-&gt;_verifyArrayIndex($request, 'latitude')) &amp;&amp; ($this-&gt;_verifyArrayIndex($request, 'longitude'))){
+                    	if(($this-&gt;_verifyArrayIndex($request, 'latitude')) &amp;&amp; ($this-&gt;_verifyArrayIndex($request, 'longitude'))){
 			        $ret = $this-&gt;_incidentsByLatLon($request['latitude'], $request['longitude']);
                                 
-                                } else {
-				    $error = array(&quot;error&quot; =&gt; $this-&gt;_getErrorMsg(001, 'latitude or longitude'));
-				}
+                        } else {
+				    		$error = array(&quot;error&quot; =&gt; $this-&gt;_getErrorMsg(001, 'latitude or longitude'));
+						}
 				break;
 				case &quot;address&quot;: //address
 				    if(($this-&gt;_verifyArrayIndex($request, 'address'))){
@@ -574,203 +576,202 @@ class Api_Controller extends Controller {
 		);
 		//	copy the form as errors, so the errors will be stored with keys corresponding to the form field names
 		$this-&gt;messages = $form;	    
-    // 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));
+    	// 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-&gt;pre_filter('trim', TRUE);
+        	//  Add some filters
+			$post-&gt;pre_filter('trim', TRUE);
 
-	// Add some rules, the input field, followed by a list of checks, carried out in order
-	$post-&gt;add_rules('incident_title','required', 'length[3,200]');
-	$post-&gt;add_rules('incident_description','required');
-	$post-&gt;add_rules('incident_date','required','date_mmddyyyy');
-	$post-&gt;add_rules('incident_hour','required','between[1,12]');
-	//$post-&gt;add_rules('incident_minute','required','between[0,59]');
+			// Add some rules, the input field, followed by a list of checks, carried out in order
+			$post-&gt;add_rules('incident_title','required', 'length[3,200]');
+			$post-&gt;add_rules('incident_description','required');
+			$post-&gt;add_rules('incident_date','required','date_mmddyyyy');
+			$post-&gt;add_rules('incident_hour','required','between[1,12]');
+			//$post-&gt;add_rules('incident_minute','required','between[0,59]');
 			
-	if($this-&gt;_verifyArrayIndex($_POST, 'incident_ampm')){
-	    if ($_POST['incident_ampm'] != &quot;am&quot; &amp;&amp; $_POST['incident_ampm'] != &quot;pm&quot;) {
-	        $post-&gt;add_error('incident_ampm','values');
-	    }
-	}
+			if($this-&gt;_verifyArrayIndex($_POST, 'incident_ampm')) {
+	    		if ($_POST['incident_ampm'] != &quot;am&quot; &amp;&amp; $_POST['incident_ampm'] != 
+					&quot;pm&quot;) {
+	        		$post-&gt;add_error('incident_ampm','values');
+	    		}
+			}
 	        
-	$post-&gt;add_rules('latitude','required','between[-90,90]');	// Validate for maximum and minimum latitude values
-	$post-&gt;add_rules('longitude','required','between[-180,180]');// Validate for maximum and minimum longitude values
-	$post-&gt;add_rules('location_name','required', 'length[3,200]');
-	$post-&gt;add_rules('incident_category','required','length[1,100]');
+			$post-&gt;add_rules('latitude','required','between[-90,90]');	// Validate for maximum and minimum latitude values
+			$post-&gt;add_rules('longitude','required','between[-180,180]');// Validate for maximum and minimum longitude values
+			$post-&gt;add_rules('location_name','required', 'length[3,200]');
+			$post-&gt;add_rules('incident_category','required','length[1,100]');
 			
-	// Validate Personal Information
-	if (!empty($post-&gt;person_first))
-	{
-	    $post-&gt;add_rules('person_first', 'length[3,100]');
-	}
+			// Validate Personal Information
+			if (!empty($post-&gt;person_first)) {
+	    		$post-&gt;add_rules('person_first', 'length[3,100]');
+			}
 			
-	if (!empty($post-&gt;person_last))
-	{
-	    $post-&gt;add_rules('person_last', 'length[3,100]');
-	}
+			if (!empty($post-&gt;person_last)) {
+	    		$post-&gt;add_rules('person_last', 'length[3,100]');
+			}
 			
-	if (!empty($post-&gt;person_email))
-	{
-	    $post-&gt;add_rules('person_email', 'email', 'length[3,100]');
-	}
+			if (!empty($post-&gt;person_email)) {
+	    		$post-&gt;add_rules('person_email', 'email', 'length[3,100]');
+			}
 			
-	// Test to see if things passed the rule checks
-	if ($post-&gt;validate()) //
-	{
-	    // SAVE LOCATION (***IF IT DOES NOT EXIST***)
-	    $location = new Location_Model();
-	    $location-&gt;location_name = $post-&gt;location_name;
-	    $location-&gt;latitude = $post-&gt;latitude;
-	    $location-&gt;longitude = $post-&gt;longitude;
-	    $location-&gt;location_date = date(&quot;Y-m-d H:i:s&quot;,time());
-	    $location-&gt;save();
+			// Test to see if things passed the rule checks
+			if ($post-&gt;validate()) {
+	    		// SAVE LOCATION (***IF IT DOES NOT EXIST***)
+	    		$location = new Location_Model();
+	    		$location-&gt;location_name = $post-&gt;location_name;
+	    		$location-&gt;latitude = $post-&gt;latitude;
+	    		$location-&gt;longitude = $post-&gt;longitude;
+	    		$location-&gt;location_date = date(&quot;Y-m-d H:i:s&quot;,time());
+	    		$location-&gt;save();
 				
-	    // SAVE INCIDENT
-	    $incident = new Incident_Model();
-	    $incident-&gt;location_id = $location-&gt;id;
-	    $incident-&gt;user_id = 0;
-	    $incident-&gt;incident_title = $post-&gt;incident_title;
-	    $incident-&gt;incident_description = $post-&gt;incident_description;
+	    		// SAVE INCIDENT
+	    		$incident = new Incident_Model();
+	    		$incident-&gt;location_id = $location-&gt;id;
+	    		$incident-&gt;user_id = 0;
+	    		$incident-&gt;incident_title = $post-&gt;incident_title;
+	    		$incident-&gt;incident_description = $post-&gt;incident_description;
 				
-	    $incident_date=split(&quot;/&quot;,$post-&gt;incident_date);
-	    // where the $_POST['date'] is a value posted by form in mm/dd/yyyy format
-	    $incident_date=$incident_date[2].&quot;-&quot;.$incident_date[0].&quot;-&quot;.$incident_date[1];
+	    		$incident_date=split(&quot;/&quot;,$post-&gt;incident_date);
+	    		/**
+			 	 * where the $_POST['date'] is a value posted by form in 
+			 	 * mm/dd/yyyy format
+			 	 */
+	    		$incident_date=$incident_date[2].&quot;-&quot;.$incident_date[0].&quot;-&quot;
+					.$incident_date[1];
 					
-	    $incident_time = $post-&gt;incident_hour . &quot;:&quot; . $post-&gt;incident_minute . &quot;:00 &quot; . $post-&gt;incident_ampm;
-	    $incident-&gt;incident_date = $incident_date . &quot; &quot; . $incident_time;
-	    $incident-&gt;incident_dateadd = date(&quot;Y-m-d H:i:s&quot;,time());
-	    $incident-&gt;save();
+	    		$incident_time = $post-&gt;incident_hour . &quot;:&quot; . $post-&gt;incident_minute . &quot;:00 &quot; . $post-&gt;incident_ampm;
+	    		$incident-&gt;incident_date = $incident_date . &quot; &quot; . $incident_time;
+	    		$incident-&gt;incident_dateadd = date(&quot;Y-m-d H:i:s&quot;,time());
+	    		$incident-&gt;save();
 				
-            // SAVE CATEGORIES
-	    //check if data is csv or a single value.
-        $pos = strpos($post-&gt;incident_category,&quot;,&quot;);
-        if( $pos === false ) {
-			//for backward compactibility. will drop support for it in the future. 
-			if( @unserialize( $post-&gt;incident_category) ) { 
-				$categories = unserialize( $post-&gt;incident_category);
-			} else {
-				$categories = array( $post-&gt;incident_category );
-			}
+            	// SAVE CATEGORIES
+	    		//check if data is csv or a single value.
+        		$pos = strpos($post-&gt;incident_category,&quot;,&quot;);
+        		if( $pos === false ) {
+					//for backward compactibility. will drop support for it in the future. 
+					if( @unserialize( $post-&gt;incident_category) ) { 
+						$categories = unserialize( $post-&gt;incident_category);
+					} else {
+						$categories = array( $post-&gt;incident_category );
+					}
         	
-        } else { 
-        	$categories = explode(&quot;,&quot;,$post-&gt;incident_category);    
-	    } 
-	    if(!empty($categories) &amp;&amp; is_array($categories)){
-	        foreach($categories as $item){
-		    	$incident_category = new Incident_Category_Model();
-		    	$incident_category-&gt;incident_id = $incident-&gt;id;
-		    	$incident_category-&gt;category_id = $item;
-		    	$incident_category-&gt;save();
-			}
-	    }
+        		} else { 
+        			$categories = explode(&quot;,&quot;,$post-&gt;incident_category);    
+	    		}
+	 
+	    		if(!empty($categories) &amp;&amp; is_array($categories)) {
+	        		foreach($categories as $item){
+		    			$incident_category = new Incident_Category_Model();
+		    			$incident_category-&gt;incident_id = $incident-&gt;id;
+		    			$incident_category-&gt;category_id = $item;
+		    			$incident_category-&gt;save();
+					}
+	    		}
 				
-	    // STEP 4: SAVE MEDIA
-	    // a. News
-	    if(!empty( $post-&gt;incident_news ) &amp;&amp; 
-		is_array($post-&gt;incident_news)){ 
-		foreach($post-&gt;incident_news as $item) {
-		    if(!empty($item))
-		    {
-		        $news = new Media_Model();
-			$news-&gt;location_id = $location-&gt;id;
-			$news-&gt;incident_id = $incident-&gt;id;
-			$news-&gt;media_type = 4;		// News
-		        $news-&gt;media_link = $item;
-			$news-&gt;media_date = date(&quot;Y-m-d H:i:s&quot;,time());
-			$news-&gt;save();
-		    }
-		}
-	    }
+	    		// STEP 4: SAVE MEDIA
+	    		// a. News
+	    		if(!empty( $post-&gt;incident_news ) &amp;&amp; 
+					is_array($post-&gt;incident_news)) { 
+						foreach($post-&gt;incident_news as $item) {
+		    				if(!empty($item)) {
+		        				$news = new Media_Model();
+								$news-&gt;location_id = $location-&gt;id;
+								$news-&gt;incident_id = $incident-&gt;id;
+								$news-&gt;media_type = 4;		// News
+		        				$news-&gt;media_link = $item;
+								$news-&gt;media_date = date(&quot;Y-m-d H:i:s&quot;,time());
+								$news-&gt;save();
+		    				}
+						}
+	    		}
 				
-	    // b. Video
-	    if( !empty( $post-&gt;incident_video) &amp;&amp; 
-	        is_array( $post-&gt;incident_video)){ 
+	    		// b. Video
+	    		if( !empty( $post-&gt;incident_video) &amp;&amp; 
+	        		is_array( $post-&gt;incident_video)){ 
 
-		foreach($post-&gt;incident_video as $item)
-		{
-		    if(!empty($item))
-		    {
-		        $video = new Media_Model();
-			$video-&gt;location_id = $location-&gt;id;
-			$video-&gt;incident_id = $incident-&gt;id;
-			$video-&gt;media_type = 2;		// Video
-			$video-&gt;media_link = $item;
-			$video-&gt;media_date = date(&quot;Y-m-d H:i:s&quot;,time());
-			$video-&gt;save();
-		    }
-		}
-	    }
+						foreach($post-&gt;incident_video as $item) {
+		    				if(!empty($item)) {
+		        				$video = new Media_Model();
+								$video-&gt;location_id = $location-&gt;id;
+								$video-&gt;incident_id = $incident-&gt;id;
+								$video-&gt;media_type = 2;		// Video
+								$video-&gt;media_link = $item;
+								$video-&gt;media_date = date(&quot;Y-m-d H:i:s&quot;,time());
+								$video-&gt;save();
+		    				}
+						}
+	    		}
 				
 				// c. Photos
 				if( !empty($post-&gt;incident_photo)){
-				    $filenames = upload::save('incident_photo');
-				    $i = 1;
-				    foreach ($filenames as $filename) {
-					    $new_filename = $incident-&gt;id . &quot;_&quot; . $i . &quot;_&quot; . time();
+					$filenames = upload::save('incident_photo');
+					$i = 1;
+					foreach ($filenames as $filename) {
+						$new_filename = $incident-&gt;id . &quot;_&quot; . $i . &quot;_&quot; . time();
 					
-					    // Resize original file... make sure its max 408px wide
-					    Image::factory($filename)-&gt;resize(408,248,Image::AUTO)
-						    -&gt;save(Kohana::config('upload.directory', TRUE) . $new_filename . &quot;.jpg&quot;);
+						// Resize original file... make sure its max 408px wide
+						Image::factory($filename)-&gt;resize(408,248,Image::AUTO)
+						    -&gt;save(Kohana::config('upload.directory', TRUE) . 
+							$new_filename . &quot;.jpg&quot;);
 					
-					    // Create thumbnail
-					    Image::factory($filename)-&gt;resize(70,41,Image::HEIGHT)
-						    -&gt;save(Kohana::config('upload.directory', TRUE) . $new_filename . &quot;_t.jpg&quot;);
+				    	// Create thumbnail
+						Image::factory($filename)-&gt;resize(70,41,Image::HEIGHT)
+						    -&gt;save(Kohana::config('upload.directory', TRUE) . 
+							$new_filename . &quot;_t.jpg&quot;);
 					
-					    // Remove the temporary file
-					    unlink($filename);
+						// Remove the temporary file
+						unlink($filename);
 					
-					    // Save to DB
-					    $photo = new Media_Model();
-					    $photo-&gt;location_id = $location-&gt;id;
-					    $photo-&gt;incident_id = $incident-&gt;id;
-					    $photo-&gt;media_type = 1; // Images
-					    $photo-&gt;media_link = $new_filename . &quot;.jpg&quot;;
-					    $photo-&gt;media_thumb = $new_filename . &quot;_t.jpg&quot;;
-					    $photo-&gt;media_date = date(&quot;Y-m-d H:i:s&quot;,time());
-					    $photo-&gt;save();
-					    $i++;
-				    }
+						// Save to DB
+						$photo = new Media_Model();
+						$photo-&gt;location_id = $location-&gt;id;
+						$photo-&gt;incident_id = $incident-&gt;id;
+						$photo-&gt;media_type = 1; // Images
+						$photo-&gt;media_link = $new_filename . &quot;.jpg&quot;;
+						$photo-&gt;media_thumb = $new_filename . &quot;_t.jpg&quot;;
+						$photo-&gt;media_date = date(&quot;Y-m-d H:i:s&quot;,time());
+						$photo-&gt;save();
+						$i++;
+					}
 				}				
 				
 				// SAVE PERSONAL INFORMATION IF ITS FILLED UP
 				if(!empty($post-&gt;person_first) || 
-				    !empty($post-&gt;person_last)){ 
+					!empty($post-&gt;person_last)){ 
 	                
-	                $person = new Incident_Person_Model();
-				    $person-&gt;location_id = $location-&gt;id;
-				    $person-&gt;incident_id = $incident-&gt;id;
-				    $person-&gt;person_first = $post-&gt;person_first;
-				    $person-&gt;person_last = $post-&gt;person_last;
-				    $person-&gt;person_email = $post-&gt;person_email;
-				    $person-&gt;person_date = date(&quot;Y-m-d H:i:s&quot;,time());
-				    $person-&gt;save();
+	            		$person = new Incident_Person_Model();
+						$person-&gt;location_id = $location-&gt;id;
+						$person-&gt;incident_id = $incident-&gt;id;
+						$person-&gt;person_first = $post-&gt;person_first;
+						$person-&gt;person_last = $post-&gt;person_last;
+						$person-&gt;person_email = $post-&gt;person_email;
+						$person-&gt;person_date = date(&quot;Y-m-d H:i:s&quot;,time());
+						$person-&gt;save();
 				}
 				
 				return 0; //success
 	            
-	        }
-	
-            // No! We have validation errors, we need to show the form again, with the errors
-	        else   
-                {
-                                // populate the error fields, if any
-                                $this-&gt;messages = arr::overwrite($this-&gt;messages, $post-&gt;errors('report'));
+			}
+        	// No! We have validation errors, we need to show the form again, with the errors
+	   		else {
+        		// populate the error fields, if any
+        		$this-&gt;messages = arr::overwrite($this-&gt;messages, 
+					$post-&gt;errors('report'));
 
-                                foreach ($this-&gt;messages as $error_item =&gt; $error_description)
-                                {
-                                    if( !is_array( $error_description ) ) {
-                                        $this-&gt;error_messages .= $error_description;
-                                        if( $error_description != end( $this-&gt;messages ) ) {
-                                            $this-&gt;error_messages .= &quot; - &quot;;
-                                        }
-                                    }
-                                }
+        		foreach ($this-&gt;messages as $error_item =&gt; $error_description) {
+            		if( !is_array( $error_description ) ) {
+                		$this-&gt;error_messages .= $error_description;
+                		if( $error_description != end( $this-&gt;messages ) ) {
+                    		$this-&gt;error_messages .= &quot; - &quot;;
+                   		}
+              		}
+            	}
                                 
 				//FAILED!!!
 				return 1; //validation error
-	        }
+	      	}
 	    }		
 		else
 		{
@@ -779,10 +780,10 @@ class Api_Controller extends Controller {
 		
 	}
 	
-	/*
-	Tag a news item to an incident
-	*/
-	function _tagMedia($incidentid, $mediatype){
+	/**
+	 * Tag a news item to an incident
+	 */
+	function _tagMedia($incidentid, $mediatype) {
 		if ($_POST) //
 	    {
 
@@ -807,9 +808,13 @@ class Api_Controller extends Controller {
 				//require a url
 				if(!$this-&gt;_verifyArrayIndex($_POST, 'url')){
 					if($this-&gt;responseType == 'json'){
-						json_encode(array(&quot;error&quot; =&gt; $this-&gt;_getErrorMsg(001, 'url')));
+						json_encode(array(&quot;error&quot; =&gt; $this-&gt;_getErrorMsg(001, 
+							'url')));
+							
 					} else {
-						$err = array(&quot;error&quot; =&gt; $this-&gt;_getErrorMsg(001, 'url'));
+						$err = array(&quot;error&quot; =&gt; $this-&gt;_getErrorMsg(001, 
+							'url'));
+							
 						return $this-&gt;_arrayAsXML($err, array());
 					}
 				} else {
@@ -905,7 +910,9 @@ class Api_Controller extends Controller {
 	    $retJsonOrXml = ''; //will hold the json/xml string to return
 
 	    //find incidents
-	    $query = &quot;SELECT id, category_title AS title, category_description AS description, category_color AS color FROM `category` WHERE category_visible = 1 ORDER BY id DESC&quot;;
+	    $query = &quot;SELECT id, category_title AS title, category_description AS 
+			description, category_color AS color FROM `category` WHERE 
+			category_visible = 1 ORDER BY id DESC&quot;;
 
 	    $items = $this-&gt;db-&gt;query($query);
 	    $i = 0;
@@ -951,7 +958,9 @@ class Api_Controller extends Controller {
 		$retJsonOrXml = ''; //will hold the json/xml string to return
 
 		//find incidents
-		$query = &quot;SELECT id, category_title, category_description, category_color FROM `category` WHERE category_visible = 1 AND id=$id ORDER BY id DESC&quot;;
+		$query = &quot;SELECT id, category_title, category_description, 
+			category_color FROM `category` WHERE category_visible = 1 
+			AND id=$id ORDER BY id DESC&quot;;
 
 	$items = $this-&gt;db-&gt;query($query);
 	$i = 0;
@@ -991,20 +1000,21 @@ class Api_Controller extends Controller {
      */
     function _getLocations($where = '', $limit = ''){
         $items = array(); //will hold the items from the query
-	$data = array(); //items to parse to json
-	$json_locations = array(); //incidents to parse to json
+		$data = array(); //items to parse to json
+		$json_locations = array(); //incidents to parse to json
 		
-	$retJsonOrXml = ''; //will hold the json/xml string to return
+		$retJsonOrXml = ''; //will hold the json/xml string to return
 
-	//find incidents
-	$query = &quot;SELECT id, location_name AS name, country_id , latitude, longitude FROM `location` $where $limit &quot;;
+		//find incidents
+		$query = &quot;SELECT id, location_name AS name, country_id , latitude, 
+			longitude FROM `location` $where $limit &quot;;
 
-	$items = $this-&gt;db-&gt;query($query);
-	$i = 0;
+		$items = $this-&gt;db-&gt;query($query);
+		$i = 0;
 		
-	$replar = array(); //assists in proper xml generation
+		$replar = array(); //assists in proper xml generation
 		
-	foreach ($items as $item){
+		foreach ($items as $item){
 	    //needs different treatment depending on the output
 	    if($this-&gt;responseType == 'json'){
 	        $json_locations[] = array(&quot;location&quot; =&gt; $item);
@@ -1013,7 +1023,7 @@ class Api_Controller extends Controller {
 	        $replar[] = 'location'.$i;
 	    }
 			
-			$i++;
+		$i++;
 	}
 		
 	//create the json array
@@ -1108,9 +1118,9 @@ class Api_Controller extends Controller {
         return $this-&gt;_getLocations($where, $limit);
     }	
 	
-	/*
-	country query abstraction
-	*/
+	/**
+	 * country query abstraction
+	 */
 	function _getCountries($where = '', $limit = ''){
 	    $items = array(); //will hold the items from the query
 	    $data = array(); //items to parse to json
@@ -1119,7 +1129,8 @@ class Api_Controller extends Controller {
 	    $retJsonOrXml = ''; //will hold the json/xml string to return
 
 		//find incidents
-		$query = &quot;SELECT id, iso, country as `name`, capital FROM `country` $where $limit&quot;;
+		$query = &quot;SELECT id, iso, country as `name`, capital 
+			FROM `country` $where $limit&quot;;
 
 		$items = $this-&gt;db-&gt;query($query);
 		$i = 0;
@@ -1198,15 +1209,15 @@ class Api_Controller extends Controller {
      */
     function _incidentsByAll($orderfield,$sort) {
         $where = &quot;\nWHERE i.incident_active = 1&quot;;
-	$sortby = &quot;\nORDER BY i.id DESC&quot;;
-	$limit = &quot;\nLIMIT 0, $this-&gt;list_limit&quot;;
-	/* Not elegant but works */
-	return $this-&gt;_getIncidents($where.$sortby, $limit);
+		$sortby = &quot;\nORDER BY i.id DESC&quot;;
+		$limit = &quot;\nLIMIT 0, $this-&gt;list_limit&quot;;
+		/* Not elegant but works */
+		return $this-&gt;_getIncidents($where.$sortby, $limit);
     }
 	
-	/*
-	get incident by id
-	*/
+	/**
+	 * get incident by id
+	 */
 	function _incidentById($id){
             $where = &quot;\nWHERE i.id = $id AND i.incident_active = 1 &quot;;
             $where .= &quot;ORDER BY i.id DESC &quot;;
@@ -1214,23 +1225,25 @@ class Api_Controller extends Controller {
 	    return $this-&gt;_getIncidents($where, $limit);
 	}
 	
-	/*
-	get the incidents by latitude and longitude
-	*/
+	/**
+	 * get the incidents by latitude and longitude.
+	 * TODO // write necessary codes to achieve this.
+	 */
 	function _incidentsByLatLon($lat, $long){
 		
 	}
 	
-	/*
-	get the incidents by address
-	*/
+	/**
+	 * get the incidents by address.
+	 * TODO // write necessary code to achieve this.
+	 */
 	function _incidentsByAddress($address){
 		
 	}
 	
-	/*
-	get the incidents by location id
-	*/
+	/**
+	 * get the incidents by location id
+	 */
 	function _incidentsByLocitionId($locid,$orderfield,$sort){
 	    $where = &quot;\nWHERE i.location_id = $locid AND i.incident_active = 1&quot;;
 	    $sortby = &quot;\nORDER BY $orderfield $sort&quot;;
@@ -1238,19 +1251,20 @@ class Api_Controller extends Controller {
 	    return $this-&gt;_getIncidents($where.$sortby, $limit);
 	}
 	
-	/*
-	get the incidents by location name
-	*/
+	/**
+	 * get the incidents by location name
+	 */
 	function _incidentsByLocationName($locname,$orderfield,$sort){
-	    $where = &quot;\nWHERE l.location_name = '$locname' AND i.incident_active = 1&quot;;
+	    $where = &quot;\nWHERE l.location_name = '$locname' AND 
+			i.incident_active = 1&quot;;
 	    $sortby = &quot;\nORDER BY $orderfield $sort&quot;;
 	    $limit = &quot;\nLIMIT 0, $this-&gt;list_limit&quot;;
             return $this-&gt;_getIncidents($where.$sortby, $limit);
 	}
 	
-	/*
-	get the incidents by category id
-	*/
+	/**
+	 * get the incidents by category id
+	 */
 	function _incidentsByCategoryId($catid,$orderfield,$sort){
 	    $where = &quot;\nWHERE c.id = $catid AND i.incident_active = 1&quot;;
 	    $sortby = &quot;\nORDER BY $orderfield $sort&quot;;
@@ -1265,39 +1279,40 @@ class Api_Controller extends Controller {
 		// Needs Extra Join
 		$join = &quot;\nINNER JOIN incident_category AS ic ON ic.incident_id = i.id&quot;; 
 		$join .= &quot;\nINNER JOIN category AS c ON c.id = ic.category_id&quot;;
-	    $where = $join.&quot;\nWHERE c.category_title = '$catname' AND i.incident_active = 1&quot;;
+	    $where = $join.&quot;\nWHERE c.category_title = '$catname' AND 
+			i.incident_active = 1&quot;;
 	    $sortby = &quot;\nORDER BY $orderfield $sort&quot;;
 	    $limit = &quot;\nLIMIT 0, $this-&gt;list_limit&quot;;
 	    return $this-&gt;_getIncidents($where.$sortby, $limit);
 	}
 	
-	/*
-	constructor
-	*/
+	/**
+	 * constructor
+	 */
 	function __construct(){
 	    $this-&gt;db = new Database;
 	    $this-&gt;list_limit = '20';
 	    $this-&gt;responseType = 'json';
 	}
 	
-	/*
-	starting point
-	*/
+	/**
+	 * starting point
+	 */
 	public function index(){
 	    //switch task
 	    $this-&gt;switchTask();
 	}
 	
-	/*
-	Creates a JSON response given an array
-	*/
+	/**
+	 * Creates a JSON response given an array
+	 */
 	function _arrayAsJSON($data){
 	    return json_encode($data);
 	}
 	
-	/*
-	converts an object to an array
-	*/
+	/**
+	 * converts an object to an array
+	 */
 	function _object2array($object) {
 	    if (is_object($object)) {
 	        foreach ($object as $key =&gt; $value) {
@@ -1310,10 +1325,10 @@ class Api_Controller extends Controller {
 	    return $array;
 	}
 	
-	/*
-	Creates a XML response given an array
-	CREDIT TO: http://snippets.dzone.com/posts/show/3391
-	*/
+	/**
+	 * Creates a XML response given an array
+	 * CREDIT TO: http://snippets.dzone.com/posts/show/3391
+	 */
 	function _write(XMLWriter $xml, $data, $replar = &quot;&quot;){
 	    foreach($data as $key =&gt; $value){
 	        if(is_a($value, 'stdClass')){
@@ -1344,20 +1359,20 @@ class Api_Controller extends Controller {
      	    }	
 	}
 	
-	/*
-	Creates a XML response given an array
-	CREDIT TO: http://snippets.dzone.com/posts/show/3391
-	*/
+	/**
+	 * Creates a XML response given an array
+	 * CREDIT TO: http://snippets.dzone.com/posts/show/3391
+	 */
     function _arrayAsXML($data, $replar = array()){
         $xml = new XMLWriter();
-	$xml-&gt;openMemory();
-	$xml-&gt;startDocument('1.0', 'UTF-8');
-	$xml-&gt;startElement('response');
+		$xml-&gt;openMemory();
+		$xml-&gt;startDocument('1.0', 'UTF-8');
+		$xml-&gt;startElement('response');
 
-	$this-&gt;_write($xml, $data, $replar);
+		$this-&gt;_write($xml, $data, $replar);
 
-	$xml-&gt;endElement();
-	return $xml-&gt;outputMemory(true);
+		$xml-&gt;endElement();
+		return $xml-&gt;outputMemory(true);
     }
 
 }
\ No newline at end of file</diff>
      <filename>application/controllers/api.php</filename>
    </modified>
    <modified>
      <diff>@@ -13,8 +13,8 @@
  * @license    http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL) 
 */
 
-class Error_Controller extends Controller {
-
+class Error_Controller extends Controller
+{
 	function __construct()
 	{
 		parent::__construct();</diff>
      <filename>application/controllers/error.php</filename>
    </modified>
    <modified>
      <diff>@@ -6,9 +6,9 @@
  * LICENSE: This source file is subject to LGPL license 
  * that is available through the world-wide-web at the following URI:
  * http://www.gnu.org/copyleft/lesser.html
- * @author     Ushahidi Team &lt;team@ushahidi.com&gt; 
+ * @author	   Ushahidi Team &lt;team@ushahidi.com&gt; 
  * @package    Ushahidi - http://source.ushahididev.com
- * @module     Feed Controller  
+ * @module	   Feed Controller	
  * @copyright  Ushahidi - http://www.ushahidi.com
  * @license    http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL) 
 * 
@@ -17,33 +17,43 @@
 class Feed_Controller extends Controller
 {
 	function __construct()
-    {
-        parent::__construct();
-    }
+	{
+		parent::__construct();
+	}
 
 	public function index($feedtype = 'rss2') 
-{
+	{
 		if(!Kohana::config('settings.allow_feed')) {
 			throw new Kohana_404_Exception();
 		}
 		if($feedtype!='atom' AND $feedtype!= 'rss2') {
 			throw new Kohana_404_Exception();
 		}
-		$feedpath = $feedtype == 'atom' ? 'feed/atom/' :  'feed/';
-		$site_url = &quot;http://&quot; . $_SERVER['SERVER_NAME'] . &quot;/&quot;;
-		$incidents = ORM::factory('incident')-&gt;where('incident_active', '1')-&gt;orderby('incident_date', 'desc')-&gt;limit(20)-&gt;find_all();
+		$feedpath = $feedtype == 'atom' ? 'feed/atom/' : 'feed/';
+		$site_url = &quot;http://&quot;.$_SERVER['SERVER_NAME'].&quot;/&quot;;
+		$incidents = ORM::factory('incident')
+						-&gt;where('incident_active', '1')
+						-&gt;orderby('incident_date', 'desc')
+						-&gt;limit(20)-&gt;find_all();
 		$items = array();
-		foreach($incidents as $incident) {
+		
+		foreach($incidents as $incident)
+		{
 			$item = array();
 			$item['title'] = $incident-&gt;incident_title;
 			$item['link'] = $site_url.'reports/view/'.$incident-&gt;id;
 			$item['description'] = $incident-&gt;incident_description;
 			$item['date'] = $incident-&gt;incident_date;
-			if($incident-&gt;location_id != 0 AND $incident-&gt;location-&gt;longitude AND $incident-&gt;location-&gt;latitude) 
-				$item['point'] = array($incident-&gt;location-&gt;latitude,$incident-&gt;location-&gt;longitude);
-			$items[] = $item;
+			
+			if($incident-&gt;location_id != 0 
+				AND $incident-&gt;location-&gt;longitude 
+				AND $incident-&gt;location-&gt;latitude)
+			{
+					$item['point'] = array($incident-&gt;location-&gt;latitude, 
+											$incident-&gt;location-&gt;longitude);
+					$items[] = $item;
+			}
 		}
-
 		
 		header(&quot;Content-Type: text/xml; charset=utf-8&quot;);
 		$view = new View('feed_'.$feedtype);</diff>
      <filename>application/controllers/feed.php</filename>
    </modified>
    <modified>
      <diff>@@ -7,9 +7,9 @@
  * LICENSE: This source file is subject to LGPL license 
  * that is available through the world-wide-web at the following URI:
  * http://www.gnu.org/copyleft/lesser.html
- * @author     Ushahidi Team &lt;team@ushahidi.com&gt; 
+ * @author	   Ushahidi Team &lt;team@ushahidi.com&gt; 
  * @package    Ushahidi - http://source.ushahididev.com
- * @module     FrontlineSMS Controller  
+ * @module	   FrontlineSMS Controller	
  * @copyright  Ushahidi - http://www.ushahidi.com
  * @license    http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL) 
 */
@@ -32,61 +32,65 @@ class Frontlinesms_Controller extends Controller
 			$message_description = $_GET['m'];
 		}
 		
-		if (!empty($frontlinesms_key) &amp;&amp; !empty($message_from) &amp;&amp; !empty($message_description))
+		if (!empty($frontlinesms_key) 
+			&amp;&amp; !empty($message_from) 
+			&amp;&amp; !empty($message_description))
 		{
 			// Is this a valid FrontlineSMS Key?
-			$keycheck = ORM::factory('settings', 1)-&gt;where('frontlinesms_key', $frontlinesms_key)-&gt;find();
-			if ($keycheck-&gt;loaded==true)
+			$keycheck = ORM::factory('settings', 1)
+							-&gt;where('frontlinesms_key', $frontlinesms_key)
+							-&gt;find();
+
+			if ($keycheck-&gt;loaded == TRUE)
 			{
 				$services = new Service_Model();
-		    	$service = $services-&gt;where('service_name', 'SMS')-&gt;find();
-			   	if (!$service) {
-		 		    return;
-			    }
+				$service = $services-&gt;where('service_name', 'SMS')-&gt;find();
+				if (!$service) 
+					return;
 			
 				$reporter_check = ORM::factory('reporter')
-					-&gt;where('service_id', $service-&gt;id)
-					-&gt;where('service_account', $message_from)
-					-&gt;find();
+									-&gt;where('service_id', $service-&gt;id)
+									-&gt;where('service_account', $message_from)
+									-&gt;find();
 
-				if ($reporter_check-&gt;loaded == true)
+				if ($reporter_check-&gt;loaded == TRUE)
 				{
 					$reporter_id = $reporter_check-&gt;id;
 				}
 				else
 				{
 					// get default reporter level (Untrusted)
-		    		$levels = new Level_Model();
-			    	$default_level = $levels-&gt;where('level_weight', 0)-&gt;find();
+					$levels = new Level_Model();
+					$default_level = $levels-&gt;where('level_weight', 0)-&gt;find();
 
-		    		$reporter = new Reporter_Model();
-		    		$reporter-&gt;service_id       = $service-&gt;id;
-		    		$reporter-&gt;service_userid   = null;
-		    		$reporter-&gt;service_account  = $message_from;
-		    		$reporter-&gt;reporter_level   = $default_level;
-		    		$reporter-&gt;reporter_first   = null;
-		    		$reporter-&gt;reporter_last    = null;
-		    		$reporter-&gt;reporter_email   = null;
-		    		$reporter-&gt;reporter_phone   = null;
-		    		$reporter-&gt;reporter_ip      = null;
-		    		$reporter-&gt;reporter_date    = date('Y-m-d');
-		    		$reporter-&gt;save();
+					$reporter = new Reporter_Model();
+					$reporter-&gt;service_id = $service-&gt;id;
+					$reporter-&gt;service_userid = null;
+					$reporter-&gt;service_account = $message_from;
+					$reporter-&gt;reporter_level = $default_level;
+					$reporter-&gt;reporter_first = null;
+					$reporter-&gt;reporter_last = null;
+					$reporter-&gt;reporter_email = null;
+					$reporter-&gt;reporter_phone = null;
+					$reporter-&gt;reporter_ip = null;
+					$reporter-&gt;reporter_date = date('Y-m-d');
+					$reporter-&gt;save();
 					$reporter_id = $reporter-&gt;id;
 				}
 				
 				// Save Message
-	    		$message = new Message_Model();
-	    		$message-&gt;parent_id = 0;
-	    		$message-&gt;incident_id = 0;
-	    		$message-&gt;user_id = 0;
-	    		$message-&gt;reporter_id = $reporter_id;
-	    		$message-&gt;message_from = $message_from;
-	    		$message-&gt;message_to = null;
-	    		$message-&gt;message = $message_description;
-	    		$message-&gt;message_type = 1; // Inbox
-	    		$message-&gt;message_date = date(&quot;Y-m-d H:i:s&quot;,time());
-	    		$message-&gt;service_messageid = null;
-	    		$message-&gt;save();
+				$message = new Message_Model();
+				$message-&gt;parent_id = 0;
+				$message-&gt;incident_id = 0;
+				$message-&gt;user_id = 0;
+				$message-&gt;reporter_id = $reporter_id;
+				$message-&gt;message_from = $message_from;
+				$message-&gt;message_to = null;
+				$message-&gt;message = $message_description;
+				$message-&gt;message_type = 1; // Inbox
+				$message-&gt;message_date = date(&quot;Y-m-d H:i:s&quot;,time());
+				$message-&gt;service_messageid = null;
+				$message-&gt;save();
 			}
 		}
 	}</diff>
      <filename>application/controllers/frontlinesms.php</filename>
    </modified>
    <modified>
      <diff>@@ -6,163 +6,172 @@
  * LICENSE: This source file is subject to LGPL license 
  * that is available through the world-wide-web at the following URI:
  * http://www.gnu.org/copyleft/lesser.html
- * @author     Ushahidi Team &lt;team@ushahidi.com&gt; 
+ * @author	   Ushahidi Team &lt;team@ushahidi.com&gt; 
  * @package    Ushahidi - http://source.ushahididev.com
- * @module     Help Controller  
+ * @module	   Help Controller	
  * @copyright  Ushahidi - http://www.ushahidi.com
  * @license    http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL) 
  */
 
-class Help_Controller extends Main_Controller {
-
-    function __construct()
-    {
-        parent::__construct();
+class Help_Controller extends Main_Controller 
+{
+	function __construct()
+	{
+		parent::__construct();
 
 		// Javascript Header
 		$this-&gt;template-&gt;header-&gt;validator_enabled = TRUE;
-    }
+	}
 
-    /**
-     * Displays all Organizations.
-     */
-    public function index() 
+	/**
+	 * Displays all Organizations.
+	 */
+	public function index() 
 	{
 		$this-&gt;template-&gt;header-&gt;this_page = 'help';
 		$this-&gt;template-&gt;content = new View('help');
+		$items_per_page = (int) Kohana::config('settings.items_per_page');
 		
 		// Pagination
 		$pagination = new Pagination(array(
-			'query_string'    =&gt; 'page',
-			'items_per_page' =&gt; (int) Kohana::config('settings.items_per_page'),
-			'total_items'    =&gt; ORM::factory('organization')-&gt;where('organization_active', '1')-&gt;count_all()
+			'query_string' =&gt; 'page',
+			'items_per_page' =&gt; $items_per_page,
+			'total_items' =&gt; ORM::factory('organization')-&gt;where('organization_active', '1')-&gt;count_all()
 		));
 
 		$organizations = ORM::factory('organization')
-            -&gt;where('organization_active', '1')
-            -&gt;orderby('organization_name', 'asc')
-            -&gt;find_all((int) Kohana::config('settings.items_per_page'), $pagination-&gt;sql_offset);
+							-&gt;where('organization_active', '1')
+							-&gt;orderby('organization_name', 'asc')
+							-&gt;find_all($items_per_page, $pagination-&gt;sql_offset);
 		
 		$this-&gt;template-&gt;content-&gt;organizations = $organizations;
 		$this-&gt;template-&gt;content-&gt;pagination = $pagination;
-        
-        //Only display stats when there are reports to display
-        if ($pagination-&gt;total_items &gt; 0)
-        {
-		    $this-&gt;template-&gt;content-&gt;pagination_stats = &quot;(Showing &quot; 
-                . (($pagination-&gt;sql_offset/(int) Kohana::config('settings.items_per_page')) + 1)
-		 	    . &quot; of &quot; . ceil($pagination-&gt;total_items/(int) Kohana::config('settings.items_per_page')) . &quot; pages)&quot;;	
-        }
-        else
-        {
-            $this-&gt;template-&gt;content-&gt;pagination_stats = &quot;&quot;;
-        }
+		
+		//Only display stats when there are reports to display
+		if ($pagination-&gt;total_items &gt; 0)
+		{
+			$this-&gt;template-&gt;content-&gt;pagination_stats = &quot;(Showing &quot; 
+				.(($pagination-&gt;sql_offset/$items_per_page) + 1)
+				.&quot; of &quot;.ceil($pagination-&gt;total_items/$items_per_page)
+				.&quot; pages)&quot;;	
+		}
+		else
+		{
+			$this-&gt;template-&gt;content-&gt;pagination_stats = &quot;&quot;;
+		}
 	}
 	
 	 /**
-     * Displays a organization
-     * @param boolean $id If id is supplied, an organization with that id will be
-     * retrieved.
-     */
-	public function view( $id = false )
+	 * Displays a organization
+	 * @param boolean $id If id is supplied, an organization with that id will be
+	 * retrieved.
+	 */
+	public function view($id = FALSE)
 	{
 		$this-&gt;template-&gt;header-&gt;this_page = 'help';
 		$this-&gt;template-&gt;content = new View('help_view');
 		
-        if ( !$id )
-        {
-            url::redirect('main');
-        }
-        else
-        {
-            $organization = ORM::factory('organization', $id);
+		if (!$id)
+		{
+			url::redirect('main');
+		}
+		else
+		{
+			$organization = ORM::factory('organization', $id);
 			
-            if ( $organization-&gt;loaded == false )	// Not Found
-            {
-                url::redirect('main');
-            }
+			if ($organization-&gt;loaded == FALSE)	// Not Found
+			{
+				url::redirect('main');
+			}
 			
 			// Comment Post?
 			// setup and initialize form field names
 			$form = array
-		    (
-		        'name'      =&gt; '',
-				'email'      =&gt; '',
-		        'phone'    =&gt; '',
-		        'message'  =&gt; '',
-				'captcha'  =&gt; ''
-		    );
+			(
+				'name' =&gt; '',
+				'email' =&gt; '',
+				'phone' =&gt; '',
+				'message' =&gt; '',
+				'captcha' =&gt; ''
+			);
 			$captcha = Captcha::factory(); 
 			$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
+			// 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($_POST);
 
-		         //  Add some filters
-		        $post-&gt;pre_filter('trim', TRUE);
+				//  Add some filters
+				$post-&gt;pre_filter('trim', TRUE);
 		
-				// Add some rules, the input field, followed by a list of checks, carried out in order
-				$post-&gt;add_rules('name','required', 'length[3,100]');
-				$post-&gt;add_rules('email','required','email', 'length[4,100]');
-				$post-&gt;add_rules('phone', 'length[3,100]');
-				$post-&gt;add_rules('message','required');
+				// Add some rules, the input field, followed by a list of checks,
+				// carried out in order
+				$post-&gt;add_rules('name', 'required', 'length[3, 100]');
+				$post-&gt;add_rules('email', 'required', 'email', 'length[4, 100]');
+				$post-&gt;add_rules('phone', 'length[3, 100]');
+				$post-&gt;add_rules('message', 'required');
 				$post-&gt;add_rules('captcha', 'required', 'Captcha::valid');
 				
 				// Test to see if things passed the rule checks
-		        if ($post-&gt;validate())
-		        {
-	                // Yes! everything is valid - Send Message
+				if ($post-&gt;validate())
+				{
+					// Yes! everything is valid - Send Message
 					if (!empty($organization-&gt;organization_email)) {
-						$to      = $organization-&gt;organization_email;
-						$from    = $post-&gt;email;
-						$subject = &quot;New Message From &quot; . Kohana::config('settings.site_name');
+						$to = $organization-&gt;organization_email;
+						$from = $post-&gt;email;
+						$subject = &quot;New Message From &quot;.Kohana::config('settings.site_name');
 						$message = &quot;&quot;;
-						$message.= &quot;Name: &quot; . $post-&gt;name . &quot;\n&quot;;
-						$message.= &quot;Email: &quot; . $post-&gt;email . &quot;\n&quot;;
-						$message.= &quot;Phone: &quot; . $post-&gt;phone . &quot;\n\n&quot;;
-						$message.= &quot;Message:\n&quot; . $post-&gt;message . &quot;\n&quot;;
+						$message.= &quot;Name: &quot;.$post-&gt;name.&quot;\n&quot;;
+						$message.= &quot;Email: &quot;.$post-&gt;email.&quot;\n&quot;;
+						$message.= &quot;Phone: &quot;.$post-&gt;phone.&quot;\n\n&quot;;
+						$message.= &quot;Message:\n&quot;.$post-&gt;message.&quot;\n&quot;;
 
 						email::send($to, $from, $subject, $message, FALSE);
 					}
 					
-					
 					// Redirect
 					url::redirect('help/view/' . $id);
 				}
 
-	            // No! We have validation errors, we need to show the form again, with the errors
-		        else   
+				// No! We have validation errors, we need to show the form again,
+				// with the errors
+				else   
 				{
-		            // repopulate the form fields
-		            $form = arr::overwrite($form, $post-&gt;as_array());
+					// repopulate the form fields
+					$form = arr::overwrite($form, $post-&gt;as_array());
 
-		            // populate the error fields, if any
-		            $errors = arr::overwrite($errors, $post-&gt;errors('message'));
+					// populate the error fields, if any
+					$errors = arr::overwrite($errors, $post-&gt;errors('message'));
 					$form_error = TRUE;
-		        }
+				}
 			}
 			
-            $this-&gt;template-&gt;content-&gt;organization_id = $organization-&gt;id;
-			$this-&gt;template-&gt;content-&gt;organization_name = $organization-&gt;organization_name;
-            $this-&gt;template-&gt;content-&gt;organization_description = nl2br($organization-&gt;organization_description);
-			$this-&gt;template-&gt;content-&gt;organization_website = text::auto_link($organization-&gt;organization_website);
-			$this-&gt;template-&gt;content-&gt;organization_email = $organization-&gt;organization_email;
-            $this-&gt;template-&gt;content-&gt;organization_phone1 = $organization-&gt;organization_phone1;
-            $this-&gt;template-&gt;content-&gt;organization_phone2 = $organization-&gt;organization_phone2;
+			$this-&gt;template-&gt;content-&gt;organization_id = $organization-&gt;id;
+			$this-&gt;template-&gt;content-&gt;organization_name 
+				= $organization-&gt;organization_name;
+			$this-&gt;template-&gt;content-&gt;organization_description 
+				= nl2br($organization-&gt;organization_description);
+			$this-&gt;template-&gt;content-&gt;organization_website 
+				= text::auto_link($organization-&gt;organization_website);
+			$this-&gt;template-&gt;content-&gt;organization_email 
+				= $organization-&gt;organization_email;
+			$this-&gt;template-&gt;content-&gt;organization_phone1 
+				= $organization-&gt;organization_phone1;
+			$this-&gt;template-&gt;content-&gt;organization_phone2 
+				= $organization-&gt;organization_phone2;
 
 			// Forms
 			$this-&gt;template-&gt;content-&gt;form = $form;
 			$this-&gt;template-&gt;content-&gt;captcha = $captcha;
-		    $this-&gt;template-&gt;content-&gt;errors = $errors;
+			$this-&gt;template-&gt;content-&gt;errors = $errors;
 			$this-&gt;template-&gt;content-&gt;form_error = $form_error;
 			
 			// Javascript Header
 			$this-&gt;template-&gt;header-&gt;js = new View('help_view_js');
-        }
+		}
 	}
-	
 }</diff>
      <filename>application/controllers/help.php</filename>
    </modified>
    <modified>
      <diff>@@ -607,6 +607,9 @@ class Reports_Controller extends Main_Controller {
 		// Video links
 		$this-&gt;template-&gt;content-&gt;incident_videos = $incident_video;
 		
+		//images 
+		$this-&gt;template-&gt;content-&gt;incident_photos = $incident_photo;
+		
 		// Create object of the video embed class
 		$video_embed = new VideoEmbed();
 		$this-&gt;template-&gt;content-&gt;videos_embed = $video_embed;</diff>
      <filename>application/controllers/reports.php</filename>
    </modified>
    <modified>
      <diff>@@ -71,7 +71,7 @@ class Scheduler_Controller extends Controller
 			
 			if (!($scheduler_last &gt; ($cronRan-45)) || $scheduler_last == 0)
 			{ // within 45 secs of cronRan time, so Execute control
-				$site_url = &quot;http://&quot; . $_SERVER['SERVER_NAME'] . &quot;/&quot;;
+				$site_url = url::base();
 				$scheduler_status = remote::status( $site_url . &quot;scheduler/&quot; . $scheduler_controller );
 				
 				// Set last time of last execution</diff>
      <filename>application/controllers/scheduler.php</filename>
    </modified>
    <modified>
      <diff>@@ -14,10 +14,49 @@
  * @license    http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL) 
  */
 
-class Alert_Model extends ORM
+class Alert_Model 
+extends ORM
 {
-	protected $has_many = array('incident' =&gt; 'alert_sent');
-	
-	// Database table name
-	protected $table_name = 'alert';
-}
+    protected $has_many = array('incident' =&gt; 'alert_sent');
+    
+    // Database table name
+    protected $table_name = 'alert';
+    
+    
+    /**
+     * Method that provides the functionality of the magic method, __set, without the overhead
+     * of having to instantiate a Reflection class to realize it, and provides for object chaining
+     * 
+     * @param string $column
+     * @param mixed $value
+     * @return Alert_Model $this for a fluent interface
+     */
+    public function set ($column, $value)
+    {   // CALL the magic method __set, with the parameters provided
+        $this-&gt;__set($column, $value);
+        
+        // RETURN $this for a fluent interface
+        return $this;
+        
+    } // END function set
+    
+    
+    /**
+     * Method that allows for the use of the set method, en masse
+     * 
+     * @param array $params
+     * @return Alert_Model $this for a fluent interface
+     */
+    public function assign (array $params = array())
+    {   // ITERATE through all of the column/value pairs provided ...
+        foreach ($params as $column =&gt; $value)
+        {   // CALL the set method with the column/value pair
+            $this-&gt;set($column, $value);
+        }
+        
+        // RETURN $this for a fluent interface
+        return $this;
+        
+    } // END function assign
+
+} // END class Alert_Model</diff>
      <filename>application/models/alert.php</filename>
    </modified>
    <modified>
      <diff>@@ -15,19 +15,8 @@
  * @license    http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL) 
  */
 ?&gt;
-	$(document).ready(function()
-	{		
-		$(&quot;.hide&quot;).click(function () {
-			$(&quot;#submitStatus&quot;).hide();
-			return false;
-		});
-	});
 
-	// Check All / Check None
-	function CheckAll( id, name )
-	{
-		$(&quot;INPUT[@name='&quot; + name + &quot;'][type='checkbox']&quot;).attr('checked', $('#' + id).is(':checked'));
-	}
+&lt;?php require SYSPATH.'../application/views/admin/form_utils_js.php' ?&gt;
 
 	// Ajax Submission
 	function commentAction ( action, confirmAction, comment_id )
@@ -67,14 +56,4 @@
 		}
 	}
 
-	//check if a checkbox has been ticked.
-	function isChecked( id )
-	{
-		var checked = $(&quot;input[@id=&quot;+id+&quot;]:checked&quot;).length
-	
-		if( checked == 0 )
-		return false
-	
-		else 
-		return true
-	}
\ No newline at end of file
+</diff>
      <filename>application/views/admin/comments_js.php</filename>
    </modified>
    <modified>
      <diff>@@ -90,6 +90,7 @@
 					&lt;li&gt;&lt;a href=&quot;&lt;?php echo url::base() ?&gt;admin/comments&quot; &lt;?php if($this_page==&quot;comments&quot;) echo &quot;class=\&quot;active\&quot;&quot; ;?&gt;&gt;Comments&lt;/a&gt;&lt;/li&gt;
 					&lt;li&gt;&lt;a href=&quot;&lt;?php echo url::base() ?&gt;admin/messages&quot; &lt;?php if($this_page==&quot;messages&quot;) echo &quot;class=\&quot;active\&quot;&quot; ;?&gt;&gt;Messages&lt;/a&gt;&lt;/li&gt;
 					&lt;?php if ($this-&gt;auth-&gt;logged_in('admin')){ ?&gt;&lt;li&gt;&lt;a href=&quot;&lt;?php echo url::base() ?&gt;admin/manage&quot; &lt;?php if($this_page==&quot;manage&quot;) echo &quot;class=\&quot;active\&quot;&quot; ;?&gt;&gt;Manage&lt;/a&gt;&lt;/li&gt;&lt;?php } ?&gt;
+					&lt;li&gt;&lt;a href=&quot;&lt;?php echo url::base() ?&gt;admin/feedback&quot; &lt;?php if($this_page==&quot;feedback&quot;) echo &quot;class=\&quot;active\&quot;&quot; ;?&gt;&gt;Feedback&lt;/a&gt;&lt;/li&gt;
 				&lt;/ul&gt;
 				&lt;!-- sub-nav --&gt;
 				&lt;ul class=&quot;sub-nav&quot;&gt;</diff>
      <filename>application/views/admin/layout.php</filename>
    </modified>
    <modified>
      <diff>@@ -33,11 +33,18 @@
 							?&gt;&lt;li&gt;&lt;a href=&quot;?type=2&quot; &lt;?php if ($type == '2') echo &quot;class=\&quot;active\&quot;&quot;; ?&gt;&gt;Outbox&lt;/a&gt;&lt;/li&gt;&lt;?php
 						}
 						?&gt;
+						&lt;li&gt;&lt;a href=&quot;?type=&lt;?php echo $type ?&gt;&amp;period=a&quot; &lt;?php if ($period == 'a') echo &quot;class=\&quot;active\&quot;&quot;; ?&gt;&gt;All&lt;/a&gt;&lt;/li&gt;
+						&lt;li&gt;&lt;a href=&quot;?type=&lt;?php echo $type ?&gt;&amp;period=d&quot; &lt;?php if ($period == 'd') echo &quot;class=\&quot;active\&quot;&quot;; ?&gt;&gt;Yesterday&lt;/a&gt;&lt;/li&gt;
+						&lt;li&gt;&lt;a href=&quot;?type=&lt;?php echo $type ?&gt;&amp;period=m&quot; &lt;?php if ($period == 'm') echo &quot;class=\&quot;active\&quot;&quot;; ?&gt;&gt;Last Month&lt;/a&gt;&lt;/li&gt;
+						&lt;li&gt;&lt;a href=&quot;?type=&lt;?php echo $type ?&gt;&amp;period=y&quot; &lt;?php if ($period == 'y') echo &quot;class=\&quot;active\&quot;&quot;; ?&gt;&gt;Last Year&lt;/a&gt;&lt;/li&gt;
 					&lt;/ul&gt;
 					&lt;!-- tab --&gt;
 					&lt;div class=&quot;tab&quot;&gt;
 						&lt;ul&gt;
 							&lt;li&gt;&lt;a href=&quot;#&quot; onClick=&quot;submitIds()&quot;&gt;DELETE&lt;/a&gt;&lt;/li&gt;
+							&lt;?php foreach($levels as $level) { ?&gt;
+								&lt;li&gt;&lt;a href=&quot;#&quot; onClick=&quot;itemAction('rank', 'Mark As &lt;?php echo $level-&gt;level_title?&gt;', '', &lt;?php echo $level-&gt;id?&gt;)&quot;&gt;&lt;?php echo $level-&gt;level_title?&gt;&lt;/a&gt;&lt;/li&gt;
+							&lt;?php } ?&gt;
 						&lt;/ul&gt;
 					&lt;/div&gt;
 				&lt;/div&gt;
@@ -64,6 +71,7 @@
 				&lt;!-- report-table --&gt;
 				&lt;?php print form::open(NULL, array('id' =&gt; 'messagesMain', 'name' =&gt; 'messagesMain')); ?&gt;
 					&lt;input type=&quot;hidden&quot; name=&quot;action&quot; id=&quot;action&quot; value=&quot;&quot;&gt;
+					&lt;input type=&quot;hidden&quot; name=&quot;level&quot;  id=&quot;level&quot;  value=&quot;&quot;&gt;
 					&lt;div class=&quot;table-holder&quot;&gt;
 						&lt;table class=&quot;table&quot;&gt;
 							&lt;thead&gt;
@@ -105,7 +113,7 @@
 									$message_type = $message-&gt;message_type;
 									?&gt;
 									&lt;tr&gt;
-										&lt;td class=&quot;col-1&quot;&gt;&lt;input name=&quot;message_id[]&quot; id=&quot;message_id&quot; value=&quot;&lt;?php echo $message_id; ?&gt;&quot; type=&quot;checkbox&quot; class=&quot;check-box&quot;/&gt;&lt;/td&gt;
+										&lt;td class=&quot;col-1&quot;&gt;&lt;input name=&quot;message_id[]&quot; value=&quot;&lt;?php echo $message_id; ?&gt;&quot; type=&quot;checkbox&quot; class=&quot;check-box&quot;/&gt;&lt;/td&gt;
 										&lt;td class=&quot;col-2&quot;&gt;
 											&lt;div class=&quot;post&quot;&gt;
 												&lt;p&gt;&lt;?php echo $message_description; ?&gt;&lt;/p&gt;
@@ -170,4 +178,4 @@
 						&lt;/table&gt;
 					&lt;/div&gt;
 				&lt;?php print form::close(); ?&gt;
-			&lt;/div&gt;
\ No newline at end of file
+			&lt;/div&gt;</diff>
      <filename>application/views/admin/messages.php</filename>
    </modified>
    <modified>
      <diff>@@ -14,6 +14,7 @@
  * @license    http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL) 
  */
 
+&lt;?php require SYSPATH.'../application/views/admin/form_utils_js.php' ?&gt;
 		
 		function limitChars(textid, limit, infodiv)
 		{
@@ -72,5 +73,46 @@
             if (confirm(&quot;Delete cannot be undone. Are you sure you want to continue?&quot;))
                 $('#messagesMain').submit(); 
         }
-
+	
+		// Ajax Submission
+		function itemAction ( action, confirmAction, item_id, level )
+		{
+			var statusMessage;
+			if( !isChecked( &quot;message&quot; ) &amp;&amp; item_id=='' )
+			{ 
+				alert('Please select at least one report.');
+			} else {
+				var answer = confirm('Are You Sure You Want To ' + confirmAction + ' items?')
+				if (answer){
+					// Set Submit Type
+					$(&quot;#action&quot;).attr(&quot;value&quot;, action);
+					
+					if (item_id != '') 
+					{
+						// Submit Form For Single Item
+						$(&quot;#item_single&quot;).attr(&quot;value&quot;, item_id);
+						$(&quot;#messagesMain&quot;).submit();
+					}
+					else
+					{
+						// Set Hidden form item to 000 so that it doesn't return server side error for blank value
+						$(&quot;#item_single&quot;).attr(&quot;value&quot;, &quot;000&quot;);
+						$(&quot;#level&quot;).attr(&quot;value&quot;, level);
+						// Submit Form For Multiple Items
+						$('#messagesMain').submit();
+/*						
+						$(&quot;input[name='incident_id[]'][checked]&quot;).each(
+							function() 
+							{
+								$(&quot;#messageMain&quot;).submit();
+							}
+						);
+*/						
+					}
+				
+				} else {
+					return false;
+				}
+			}
+		}
 		</diff>
      <filename>application/views/admin/messages_js.php</filename>
    </modified>
    <modified>
      <diff>@@ -13,21 +13,9 @@
  * @copyright  Ushahidi - http://www.ushahidi.com
  * @license    http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL) 
  */
-		
-		$(document).ready(function()
-		{		
-			$(&quot;.hide&quot;).click(function () {
-				$(&quot;#submitStatus&quot;).hide();
-				return false;
-			});
-		});
-		
-		// Check All / Check None
-		function CheckAll( id, name )
-		{
-			$(&quot;INPUT[name='&quot; + name + &quot;'][type='checkbox']&quot;).attr('checked', $('#' + id).is(':checked'));
-		}
-		
+
+&lt;?php require SYSPATH.'../application/views/admin/form_utils_js.php' ?&gt;
+
 		// Ajax Submission
 		function reportAction ( action, confirmAction, incident_id )
 		{
@@ -66,14 +54,4 @@
 			}
 		}
 		
-		//check if a checkbox has been ticked.
-		function isChecked( id )
-		{
-			var checked = $(&quot;input[id=&quot;+id+&quot;]:checked&quot;).length
-			
-			if( checked == 0 )
-			return false
-			
-			else 
-			return true
-		}
+</diff>
      <filename>application/views/admin/reports_js.php</filename>
    </modified>
    <modified>
      <diff>@@ -20,7 +20,6 @@
 					&lt;div class=&quot;report-form&quot;&gt;
 						&lt;?php
 						if ($form_error) {
-							print_r($errors);
 						?&gt;
 							&lt;!-- red-box --&gt;
 							&lt;div class=&quot;red-box&quot;&gt;</diff>
      <filename>application/views/admin/settings.php</filename>
    </modified>
    <modified>
      <diff>@@ -68,10 +68,9 @@
 									&lt;p&gt;
 										FrontlineSMS is free open source software that turns a laptop and a mobile phone into a central communications hub. Once installed, the program enables users to send and receive text messages with large groups of people through mobile phones. Click on the grey box to request a download from FrontlineSMS.com.
 									&lt;/p&gt;
-									&lt;a href=&quot;http://www.frontlinesms.com/download/&quot; target=&quot;_blank&quot; class=&quot;no_border&quot;&gt;
+									&lt;a href=&quot;http://www.frontlinesms.com/download/&quot; class=&quot;no_border&quot;&gt;
 										&lt;img src=&quot;&lt;?php echo url::base() ?&gt;media/img/admin/download_frontline_engine.gif&quot; /&gt;
 									&lt;/a&gt;
-						
 								&lt;/td&gt;
 							&lt;/tr&gt;
 							&lt;tr&gt;</diff>
      <filename>application/views/admin/sms.php</filename>
    </modified>
    <modified>
      <diff>@@ -21,43 +21,50 @@
 				&lt;div class=&quot;big-block-bottom&quot;&gt;
 					&lt;h1&gt;Get Alerts&lt;/h1&gt;
 					&lt;!-- green-box/ red-box depending on verification result --&gt;
-					&lt;?php
-					if ($errno == ER_CODE_NOT_FOUND)
-					{
-						echo &quot;&lt;div class=\&quot;red-box\&quot;&gt;&quot;;
-						echo &quot;&lt;div class=\&quot;alert_response\&quot;&gt;&quot;;
-						echo Kohana::lang('alerts.code_not_found');
-                   		echo &quot;&lt;/div&gt;&quot;;
-
-						echo &quot;&lt;div class=\&quot;alert_confirm\&quot;&gt;&quot;;
-								
-								print form::open('/alerts/verify');
-								print form::input('alert_code', '');
-								print &quot;&amp;nbsp;&amp;nbsp;&quot;;
-								print form::submit('button', 'Confirm', ' class=&quot;btn_blue&quot;');
-								print form::close();
-						echo &quot;&lt;/div&gt;&quot;;
-						echo &quot;&lt;/div&gt;&quot;;
-					}
-					elseif ($errno == ER_CODE_ALREADY_VERIFIED)
-					{
-						echo &quot;&lt;div class=\&quot;red-box\&quot;&gt;&quot;;
-						echo &quot;&lt;div class=\&quot;alert_response\&quot; align=\&quot;center\&quot;&gt;&quot;;
-						echo Kohana::lang('alerts.code_already_verified');
-                        echo &quot;&lt;/div&gt;&quot;;
-                   		echo &quot;&lt;/div&gt;&quot;;
-					}
-
-                    elseif ($errno == ER_CODE_VERIFIED)
-                    {
-                        echo &quot;&lt;div class=\&quot;green-box\&quot;&gt;&quot;;
-                        echo &quot;&lt;div class=\&quot;alert_response\&quot; align=\&quot;center\&quot;&gt;&quot;;
-                   		echo Kohana::lang('alerts.code_verified');
-                        echo &quot;&lt;/div&gt;&quot;;
-                        echo &quot;&lt;/div&gt;&quot;;
-                    }
-
-                    ?&gt;
+&lt;?php
+    // SWITCH based on the value of the $errno
+    switch ($errno) : 
+    
+        // IF the code provided was not found ...
+        case Alert_Model::ER_CODE_NOT_FOUND:
+?&gt;
+                        &lt;div class=&quot;red-box&quot;&gt;
+                            &lt;div class=&quot;alert_response&quot;&gt;
+                                &lt;?php echo Kohana::lang('alerts.code_not_found'); ?&gt;
+                            &lt;/div&gt;
+                            &lt;div class=&quot;alert_confirm&quot;&gt;
+                                &lt;?php echo form::open('/alerts/verify'); ?&gt;
+                                &lt;?php echo form::input('alert_code', ''); ?&gt;
+                                &lt;?php echo form::submit('button', 'Confirm', ' class=&quot;btn_blue&quot;'); ?&gt;
+                                &lt;?php echo form::close(); ?&gt;
+                            &lt;/div&gt;
+                        &lt;/div&gt;
+&lt;?php
+        break;
+        
+        // IF the code provided means the alert has already been verified ...
+        case Alert_Model::ER_CODE_ALREADY_VERIFIED
+?&gt;
+                        &lt;div class=&quot;red-box&quot;&gt;
+                            &lt;div class=&quot;alert_response&quot; align=&quot;center&quot;&gt;
+                                &lt;?php echo Kohana::lang('alerts.code_already_verified'); ?&gt;
+                            &lt;/div&gt;
+                        &lt;/div&gt;
+&lt;?php
+        // IF the code provided means the code is now verified ...
+        case Alert_Model::ER_CODE_VERIFIED;
+?&gt;
+                        &lt;div class=&quot;green-box&quot;&gt;
+                            &lt;div class=&quot;alert_response&quot; align=&quot;center&quot;&gt;
+                                &lt;?php echo Kohana::lang('alerts.code_verified'); ?&gt;
+                            &lt;/div&gt;
+                        &lt;/div&gt;
+&lt;?php
+        break;
+        
+    // END the conditional regarding the status of the $errno passed to the view    
+    endswitch; 
+?&gt;
                 &lt;/div&gt;
 			&lt;/div&gt;
 		&lt;/div&gt;</diff>
      <filename>application/views/alerts_verify.php</filename>
    </modified>
    <modified>
      <diff>@@ -50,7 +50,7 @@
                 &lt;/form&gt;
               &lt;/div&gt;
               &lt;div id=&quot;graph&quot; class=&quot;graph-holder&quot;&gt;&lt;/div&gt;
-              &lt;a href=&quot;#&quot;&gt;&lt;div class=&quot;btn-more&quot; onclick=&quot;gTimeline.resetPlay().play()&quot;&gt;(Re-)Play&lt;/div&gt;&lt;/a&gt;
+              &lt;a href=&quot;#&quot;&gt;&lt;div class=&quot;btn-more&quot; id=&quot;playTimeline&quot;&gt;(Re-)Play&lt;/div&gt;&lt;/a&gt;
             &lt;/div&gt;
             &lt;div class=&quot;category&quot;&gt;
               &lt;strong class=&quot;title&quot;&gt;CATEGORY FILTER&lt;/strong&gt;</diff>
      <filename>application/views/main.php</filename>
    </modified>
    <modified>
      <diff>@@ -18,7 +18,7 @@
 		// Map JS
 		jQuery(function() {
 			var map_layer;
-			var markers;
+			markers = null;
 			var catID = '';
 			
 			/*
@@ -78,13 +78,14 @@
 			map.addControl(new OpenLayers.Control.PanZoomBar());
 			map.addControl(new OpenLayers.Control.MousePosition());
 			map.addControl(new OpenLayers.Control.LayerSwitcher());		
+			gMap = map;
 			
 			
 			// Create the markers layer
 			function addMarkers(catID,startDate,endDate, currZoom, currCenter, mediaType){
-				
+			
 				// Set Feature Styles
-				var style = new OpenLayers.Style({
+				style = new OpenLayers.Style({
 					'externalGraphic': &quot;${icon}&quot;,
 					pointRadius: &quot;${radius}&quot;,
 					fillColor: &quot;${color}&quot;,
@@ -124,8 +125,8 @@
 						color: function(feature)
 						{
 							if ( typeof(feature.cluster) != 'undefined' &amp;&amp; 
-							     feature.cluster.length &lt; 2 || 
-							     (typeof(catID) != 'undefined' &amp;&amp; catID.length &gt; 0 &amp;&amp; catID != 0))
+							     (feature.cluster.length &lt; 2 || 
+							     (typeof(catID) != 'undefined' &amp;&amp; catID.length &gt; 0 &amp;&amp; catID != 0)))
 							{
 								return &quot;#&quot; + feature.cluster[0].data.color;
 							}
@@ -245,6 +246,8 @@
 				};
 				map.setCenter(myPoint, myZoom);
 			}
+			
+			gAddMarkers = addMarkers;
 			addMarkers();
 			
 			function onMapStartLoad(event) {
@@ -348,20 +351,21 @@
 						if (!currentCat || currentCat == '0') {
 							currentCat = 'ALL';
 						}
-						$.timeline({categoryId: currentCat, startTime: new Date(startDate * 1000), 
+						gTimeline = $.timeline({categoryId: currentCat, startTime: new Date(startDate * 1000), 
 						    endTime: new Date(endDate * 1000), mediaType: gMediaType,
 							graphData: allGraphData[0][currentCat], 
 							url: &quot;&lt;?php echo url::base() . 'json/timeline/' ?&gt;&quot;
-						}).plot();
+						});
+						gTimeline.plot();
 					}
 				}
-			}); //.hide();
+			}); 
 		
 			// Graph
 			var allGraphData = [&lt;?php echo $all_graphs ?&gt;];
 			var plotPeriod = $.timelinePeriod(allGraphData[0]['ALL'].data);
 			var startTime = $.monthStartTime(plotPeriod[0]) / 1000;
-			var endTime = $.monthEndTime(plotPeriod[1]) / 1000;
+			var endTime = $.monthEndDateTime(plotPeriod[1]) / 1000;
 			$(&quot;#startDate&quot;).val(startTime);
 			$(&quot;#endDate&quot;).val(endTime);
 			gCategoryId = 'ALL';
@@ -381,11 +385,12 @@
 					
 					var startTime = new Date($(&quot;#startDate&quot;).val() * 1000);
 					var endTime = new Date($(&quot;#endDate&quot;).val() * 1000);
-					$.timeline({categoryId: catId, startTime: startTime, endTime: endTime,
+					gTimeline = $.timeline({categoryId: catId, startTime: startTime, endTime: endTime,
 						graphData: graphData,
 						url: &quot;&lt;?php echo url::base() . 'json/timeline/' ?&gt;&quot;,
 						mediaType: gMediaType
-					}).plot();
+					});
+					gTimeline.plot();
 				});
 			}
 			
@@ -409,9 +414,14 @@
 				
 				$('.filter a').attr('class', '');
 				$(this).addClass('active');
-				$.timeline({categoryId: gCategoryId, startTime: startTime, 
+				gTimeline = $.timeline({categoryId: gCategoryId, startTime: startTime, 
 				    endTime: endTime, mediaType: gMediaType,
 					url: &quot;&lt;?php echo url::base() . 'json/timeline/' ?&gt;&quot;
-				}).plot();
+				});
+				gTimeline.plot();
+			});
+			
+			$('#playTimeline').click(function() {
+				gTimeline.resetPlay().play();
 			});
 		});</diff>
      <filename>application/views/main_cluster_js.php</filename>
    </modified>
    <modified>
      <diff>@@ -239,7 +239,7 @@
 			allGraphData = [&lt;?php echo $all_graphs ?&gt;];
 			var plotPeriod = $.timelinePeriod(allGraphData[0]['ALL'].data);
 			var startTime = $.monthStartTime(plotPeriod[0]) / 1000;
-			var endTime = $.monthEndTime(plotPeriod[1]) / 1000;
+			var endTime = $.monthEndDateTime(plotPeriod[1]) / 1000;
 			$(&quot;#startDate&quot;).val(startTime);
 			$(&quot;#endDate&quot;).val(endTime);
 			gCategoryId = 'ALL';
@@ -295,4 +295,8 @@
 				});
 				gTimeline.plot();
 			});
+			
+			$('#playTimeline').click(function() {
+				gTimeline.resetPlay().play();
+			});
 		});</diff>
      <filename>application/views/main_js.php</filename>
    </modified>
    <modified>
      <diff>@@ -119,6 +119,10 @@
 		    &lt;/div&gt;
 		    &lt;!-- end incident block &lt;&gt; start other report --&gt;
 		    &lt;div class=&quot;blocks-holder&quot;&gt;
+			 &lt;?php
+			 	if( count($incident_photos) &gt; 0 ) 
+				{
+			 ?&gt;
 		      &lt;!-- start images --&gt;
 		      &lt;div class=&quot;small-block images&quot;&gt;
 		        &lt;h3&gt;Images&lt;/h3&gt;
@@ -131,6 +135,48 @@
 		        &lt;/div&gt;
 		      &lt;/div&gt;
 		      &lt;!-- end images &lt;&gt; start side block --&gt;
+			  &lt;?php } else {?&gt; 
+			  &lt;!-- start mainstream news of incident --&gt;	
+				&lt;div class=&quot;small-block images&quot;&gt;
+		          &lt;h3&gt;Related Mainstream News of Incident&lt;/h3&gt;
+		          &lt;div class=&quot;block-bg&quot;&gt;
+		            &lt;div class=&quot;block-top&quot;&gt;
+		              &lt;div class=&quot;block-bottom&quot;&gt;
+		                &lt;ul&gt;
+		                  &lt;li&gt;
+		                    &lt;ul class=&quot;title&quot;&gt;
+		                      &lt;li class=&quot;w-01&quot;&gt;TITLE&lt;/li&gt;
+		                      &lt;li class=&quot;w-02&quot;&gt;SOURCE&lt;/li&gt;
+		                      &lt;li class=&quot;w-03&quot;&gt;DATE&lt;/li&gt;
+		                    &lt;/ul&gt;
+		                  &lt;/li&gt;
+						&lt;?php
+						foreach ($feeds as $feed)
+						{
+							$feed_id = $feed-&gt;id;
+							$feed_title = text::limit_chars($feed-&gt;item_title, 40, '...', True);
+							$feed_link = $feed-&gt;item_link;
+							$feed_date = date('M j Y', strtotime($feed-&gt;item_date));
+							$feed_source = text::limit_chars($feed-&gt;feed-&gt;feed_name, 15, &quot;...&quot;);
+							?&gt;
+							&lt;li&gt;
+								&lt;ul&gt;
+									&lt;li class=&quot;w-01&quot;&gt;
+									&lt;a href=&quot;&lt;?php echo $feed_link; ?&gt;&quot; target=&quot;_blank&quot;&gt;
+									&lt;?php echo $feed_title ?&gt;&lt;/a&gt;&lt;/li&gt;
+									&lt;li class=&quot;w-02&quot;&gt;&lt;?php echo $feed_source; ?&gt;&lt;/li&gt;
+									&lt;li class=&quot;w-03&quot;&gt;&lt;?php echo $feed_date; ?&gt;&lt;/li&gt;
+								&lt;/ul&gt;
+							&lt;/li&gt;
+							&lt;?php
+						}
+						?&gt;
+		                &lt;/ul&gt;
+		              &lt;/div&gt;
+		            &lt;/div&gt;
+		          &lt;/div&gt;
+		        &lt;/div&gt;
+			 &lt;?php } ?&gt;
 		      &lt;div class=&quot;side-block&quot;&gt;
 		        &lt;div class=&quot;small-block&quot;&gt;
 		          &lt;h3&gt;Incident Report(s)&lt;/h3&gt;
@@ -163,6 +209,10 @@
 		            &lt;/div&gt;
 		          &lt;/div&gt;
 		        &lt;/div&gt;
+				&lt;?php 
+				if( $incident_photos &lt;= 0) 
+				{
+				?&gt; 
 		        &lt;div class=&quot;small-block&quot;&gt;
 		          &lt;h3&gt;Related Mainstream News of Incident&lt;/h3&gt;
 		          &lt;div class=&quot;block-bg&quot;&gt;
@@ -203,9 +253,9 @@
 		          &lt;/div&gt;
 		        &lt;/div&gt;
 		      &lt;/div&gt;
+				&lt;?php }  ?&gt;
 		      &lt;!-- end side block --&gt;
 		    &lt;/div&gt;
-			&lt;br /&gt;
 			&lt;!-- start videos --&gt;
 			&lt;?php
 				if( count($incident_videos) &gt; 0 ) 
@@ -213,6 +263,7 @@
 
 			?&gt;
 			    &lt;div class=&quot;small-block images&quot;&gt;
+					&lt;br /&gt;
 			    	&lt;h3&gt;Videos&lt;/h3&gt;
 					&lt;div class=&quot;block-bg&quot;&gt;
 			          &lt;div class=&quot;block-top&quot;&gt;</diff>
      <filename>application/views/reports_view.php</filename>
    </modified>
    <modified>
      <diff>@@ -14,7 +14,6 @@
  * @license    http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL) 
  */
 
-
 (function($) { // hide the namespace
 
 	function Timeline(options) {
@@ -38,6 +37,10 @@
 		
 		this.graphData = [];
 		this.playCount = 0;
+		this.addMarkers = null;
+		if (typeof(gAddMarkers) != 'undefined') {
+			this.addMarkers = gAddMarkers;
+		}
 	    
 		if (options) {
 			if (options.categoryId == '0') {
@@ -157,15 +160,24 @@
 			playTimeline.plot();
 			gStartTime = new Date(plotData.data[0][0]);
 			gPlayEndDate = playTimeline.graphData[playTimeline.graphData.length-1][0] / 1000;
+			playTimeline.plotMarkers(style, markers, gPlayEndDate);
 			this.playCount++;
 			gTimeline = this;
-			gTimelinePlayHandle = window.setTimeout(&quot;gTimeline.play(); playTimeline.plotMarkers(style, markers, gPlayEndDate)&quot;,1000);
+			gTimelinePlayHandle = window.setTimeout(&quot;gTimeline.play()&quot;,2000);
 			return this;
 		};
 		
 		this.plotMarkers = function(style, markers, endDate) {
 			var startDate = this.startTime.getTime() / 1000;
 			var endDate = endDate || this.endTime.getTime() / 1000;
+
+			// XXX NOTE: Change this for intervals other than monthly if supported
+			endDate = $.monthEndTime(endDate * 1000) / 1000;
+			
+			if (this.addMarkers) {	
+				this.addMarkers(gCategoryId, '', endDate, gMap.getZoom(), gMap.getCenter(), gMediaType);
+				return this;
+			}
 			
 			var sliderfilter = new OpenLayers.Rule({
 				filter: new OpenLayers.Filter.Comparison(
@@ -217,26 +229,31 @@
 	 * Returns timestamp of the first day of Month of the given timestamp
 	 */
 	$.monthStartTime = function(timestamp) {
-		var startTime = new Date(timestamp - 
-			                     ((new Date(timestamp).getDate()-1) * 24*60*60*1000)).getTime();
-		var startDate = new Date(startTime);
-		return startTime - (startDate.getHours()   * 60*60*1000) - 
-		                   (startDate.getMinutes() * 60*1000) -
-		                   (startDate.getSeconds() * 1000);
+		var startDate = new Date(timestamp);
+		startDate.setDate(1);
+		startDate.setHours(0);
+		startDate.setMinutes(0);
+		startDate.setSeconds(0);
+		return startDate.getTime();
 	};
 	
 	/*
 	 * Returns timestamp of the last day of month of the given timestamp
 	 */
+	$.monthEndDateTime = function(timestamp) {
+		endDate = new Date(timestamp);
+		endDate.setDate($.monthDays(endDate.getYear(), endDate.getMonth()));
+		endDate.setHours(0);
+		endDate.setMinutes(0);
+		endDate.setSeconds(0);
+		return endDate.getTime();	
+	};
+	
+	/*
+	 * Returns timestamp of the last second in the month of given timestamp
+	 */
 	$.monthEndTime = function(timestamp) {
-		var givenDate = new Date(timestamp);
-		var endTime = timestamp + 
-		              (($.monthDays(givenDate.getYear(), givenDate.getMonth()) - 
-		               new Date(timestamp).getDate()) * 24*60*60*1000);
-		var endDate = new Date(endTime);
-		return endTime - (endDate.getHours()   * 60*60*1000) - 
-		                 (endDate.getMinutes() * 60*1000) -
-		                 (endDate.getSeconds() * 1000);
+		return $.monthEndDateTime(timestamp) + (59*1000)+(59*60*1000)+(23*60*60*1000);
 	};
 		
 })(jQuery);</diff>
      <filename>media/js/timeline.js</filename>
    </modified>
    <modified>
      <diff>@@ -654,6 +654,7 @@ CREATE TABLE IF NOT EXISTS `message`
 `message_detail` text default NULL,
 `message_type` TINYINT default 1 COMMENT '1 - INBOX, 2 - OUTBOX (From Admin)',
 `message_date` DATETIME default NULL,
+`message_level` TINYINT NULL DEFAULT 0, 
 PRIMARY KEY (`id`)
 );
 </diff>
      <filename>sql/ushahidi.sql</filename>
    </modified>
    <modified>
      <diff>@@ -13,4 +13,4 @@ $lang = array
 	E_USER_WARNING       =&gt; array( 1, 'Warning Message',   ''),
 	E_STRICT             =&gt; array( 2, 'Strict Mode Error', ''),
 	E_NOTICE             =&gt; array( 2, 'Runtime Message',   ''),
-);
\ No newline at end of file
+);</diff>
      <filename>system/i18n/en_US/errors.php</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>2d8c076357df6670889cf735194c63d0cdfe794a</id>
    </parent>
  </parents>
  <author>
    <name>David Kobia</name>
    <email>david@ushahidi.com</email>
  </author>
  <url>http://github.com/ushahidi/Ushahidi_Web/commit/f57b0e14e820680417a51ad3503f37166bfcd33e</url>
  <id>f57b0e14e820680417a51ad3503f37166bfcd33e</id>
  <committed-date>2009-07-10T04:58:45-07:00</committed-date>
  <authored-date>2009-07-10T04:58:45-07:00</authored-date>
  <message>* Fixed Merge Conflict</message>
  <tree>091d8d9c404fd2b0ca133557aaa74bb217e905fd</tree>
  <committer>
    <name>David Kobia</name>
    <email>david@ushahidi.com</email>
  </committer>
</commit>
