public function index()
 {
     $projects = array();
     $i = 0;
     foreach (Project::all() as $project) {
         $projects[$i]['color'] = $project['color'];
         $projects[$i]['name'] = $project['name'];
         $projects[$i]['numContact'] = DB::table('johng_sm_contacts_projects')->where('project_id', $project['id'])->count();
         $i++;
     }
     $this->vars['projects'] = $projects;
     $this->asExtension('ListController')->index();
 }
 public function onAddSubscriber()
 {
     $error = false;
     $message = 'Thank You for Subscribing';
     $project_id = post('project');
     $data = ["email" => post('email'), "firstname" => post('firstname'), "lastname" => post('lastname'), "latitude" => post('latitude'), "longitude" => post('longitude'), "contact_att" => post('contact_att'), "debug" => post('debug') ? post('debug') : false];
     try {
         if (!Project::find($project_id)) {
             $error = true;
             $message = 'Project Not Found!';
         } else {
             // Add Contact to the Database.
             $contact = Contact::create($data);
             $contact->projects()->attach($project_id);
             // Send eMail
             $sm = $this->onSendMail($data);
             $this->page['result'] = $message;
         }
     } catch (\Exception $e) {
         $this->page['error'] = $error;
         $this->page['result'] = $e->getMessage();
     }
 }
 /**
  * @return array of Project Name
  */
 public function getNameOptions()
 {
     return Project::lists('name', 'id');
 }