Esempio n. 1
0
 /**
  * Generates the JSON used to display the User Group listing.
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @since [v2.0]
  * @return String JSON
  */
 public function getDatatable()
 {
     if (Input::has('offset')) {
         $offset = e(Input::get('offset'));
     } else {
         $offset = 0;
     }
     if (Input::has('limit')) {
         $limit = e(Input::get('limit'));
     } else {
         $limit = 50;
     }
     if (Input::get('sort') == 'name') {
         $sort = 'first_name';
     } else {
         $sort = e(Input::get('sort'));
     }
     // Grab all the groups
     $groups = Group::with('users')->orderBy('name', 'ASC');
     //$users = Company::scopeCompanyables($users);
     if (Input::has('search')) {
         $groups = $users->TextSearch(e(Input::get('search')));
     }
     $order = Input::get('order') === 'asc' ? 'asc' : 'desc';
     $allowed_columns = ['name', 'created_at'];
     $sort = in_array($sort, $allowed_columns) ? $sort : 'name';
     $groups = $groups->orderBy($sort, $order);
     $groupsCount = $groups->count();
     $groups = $groups->skip($offset)->take($limit)->get();
     $rows = array();
     foreach ($groups as $group) {
         $group_names = '';
         $inout = '';
         $actions = '<nobr>';
         $actions .= '<a href="' . route('update/group', $group->id) . '" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> ';
         if (!config('app.lock_passwords')) {
             $actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('delete/group', $group->id) . '" data-content="' . trans('admin/groups/message.delete.confirm') . '" data-title="Delete ' . htmlspecialchars($group->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a> ';
         } else {
             $actions .= ' <span class="btn delete-asset btn-danger btn-sm disabled"><i class="fa fa-trash icon-white"></i></span>';
         }
         $actions .= '</nobr>';
         $rows[] = array('id' => $group->id, 'name' => $group->name, 'users' => $group->users->count(), 'created_at' => $group->created_at->format('Y-m-d'), 'actions' => $actions ? $actions : '');
     }
     $data = array('total' => $groupsCount, 'rows' => $rows);
     return $data;
 }
Esempio n. 2
0
 /**
  * Show the application dashboard to the user.
  *
  * @param Group $group
  *
  * @return Response
  */
 public function index(Group $group, Envoy $envoy)
 {
     $groups = $group->with('sites')->get();
     $siteJsonLink = route('site.json');
     $this->setJavascriptData(compact('groups', 'siteJsonLink'));
 }
Esempio n. 3
0
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/
$app->get('/', function () use($app) {
    return $app->welcome();
});
// Auth endpoint
$app->post('v1/auth/login', 'AuthController@postLogin');
$app->group(['prefix' => 'v1', 'middleware' => 'jwt.auth'], function ($app) {
    // Get a group and its users
    $app->get('/group/{id}', function ($id) {
        $group = Group::with('user')->with('users')->find($id);
        return response()->json($group);
    });
    // Get the timeline of certain group
    $app->get('/group/{id}/messages', function ($id) {
    });
    // Create a group
    $app->post('/group', function (Request $request) {
        $user = JWTAuth::parseToken()->authenticate();
        $group = new Group();
        $group->name = $request->input('name');
        $group->description = $request->input('description');
        $group->user_id = $user->id;
        $group->save();
        return response()->json($group);
    });
Esempio n. 4
0
 public function sendMessage($society, $type)
 {
     $soc = Society::find($society);
     $input = Input::all();
     $alldat = array();
     if ($input['leaderoptions'] == "everyone") {
         $allhouseholds = Household::with('individual')->where('society_id', '=', $society)->get();
         foreach ($allhouseholds as $hhh) {
             foreach ($hhh->individual as $iii) {
                 if ($iii->id == $hhh->householdcell) {
                     $dum = self::PopulateRecipient($iii);
                     if ($dum['cellphone'] != "" and $iii->memberstatus == "member") {
                         $alldat[$iii->id] = $dum;
                     }
                 }
             }
         }
     } elseif (isset($input['groups'])) {
         $groups = $input['groups'];
         if ($input['leaderoptions'] == "allmembers") {
             foreach ($groups as $thisgroup) {
                 $group = Group::with('individual')->find($thisgroup);
                 foreach ($group->individual as $indiv) {
                     $dum = self::PopulateRecipient($indiv);
                     $alldat[$indiv->id] = $dum;
                 }
             }
         } elseif ($input['leaderoptions'] == "leadersonly" or $input['leaderoptions'] == "leadersandlist") {
             foreach ($groups as $thisgroup) {
                 $group = Group::with('individual')->find($thisgroup);
                 foreach ($group->individual as $indiv) {
                     if ($group->contact == $indiv->id) {
                         $dum = self::PopulateRecipient($indiv);
                         if (!isset($alldat[$indiv->id])) {
                             $alldat[$indiv->id] = $dum;
                         }
                         if ($input['leaderoptions'] == "leadersandlist") {
                             if (isset($alldat[$indiv->id]['grouplist'])) {
                                 $alldat[$indiv->id]['grouplist'] = $alldat[$indiv->id]['grouplist'] . $group->id . ",";
                             } else {
                                 $alldat[$indiv->id]['grouplist'] = $group->id . ",";
                             }
                         }
                     }
                 }
             }
         }
     }
     if (isset($input['indivs'])) {
         foreach ($input['indivs'] as $individ) {
             $indiv = Individual::find($individ);
             $dum = self::PopulateRecipient($indiv);
             if (!isset($alldat[$individ])) {
                 $alldat[$individ] = $dum;
             }
         }
     }
     if ($type == "email") {
         if (isset($input['htmlbody'])) {
             $message = nl2br($input['message']) . file_get_contents($input['htmlbody']);
         } else {
             $message = nl2br($input['message']);
         }
         $message = HTML::decode($message);
         $subject = $input['subject'];
         $sender = Input::get('sender');
         Mail::queue('messages.message', array('msg' => $message), function ($message) use($subject, $soc, $alldat, $sender) {
             if (Input::file('attachment')) {
                 $message->attach(Input::file('attachment'), array('as' => Input::file('attachment')->getClientOriginalName(), 'mime' => Input::file('attachment')->getMimeType()));
             }
             foreach ($alldat as $thisrec) {
                 $name = $thisrec['name'];
                 $email = $thisrec['email'];
                 $household = $thisrec['household'];
                 if (isset($thisrec['grouplist'])) {
                     $grouplist = $thisrec['grouplist'];
                 } else {
                     $grouplist = "No group";
                 }
                 $message->from('*****@*****.**', $soc->society . " Methodist Church");
                 $message->to($email, $name)->replyTo($sender);
                 if ($subject == "") {
                     $subject = "Email from " . $soc->society . " Methodist Church";
                 }
                 if ($grouplist != "No group") {
                     $ggl = explode(",", substr($grouplist, 0, -1));
                     foreach ($ggl as $gl) {
                         $repdata = app('App\\Http\\Controllers\\ReportsController')->show($gl, true);
                         $tg = Group::find($gl);
                         $message->attachData($repdata, $tg->groupname . ".pdf");
                     }
                 }
                 $message->subject($subject);
             }
         });
         $results = array();
         foreach ($alldat as $tdat) {
             $result['name'] = $tdat['name'];
             $result['address'] = $tdat['email'];
             $result['household'] = $tdat['household'];
             $results[] = $result;
         }
     } else {
         $final = array();
         foreach ($alldat as $thisdat) {
             $ndx = intval($thisdat['household']);
             if (Input::get('economy') == "household") {
                 if (array_key_exists($ndx, $final)) {
                     $keyhouse = Household::find($ndx)->householdcell;
                     $keycell = Individual::find($keyhouse);
                     if (SMSfunctions::checkcell($keycell->cellphone)) {
                         $final[$ndx]['cellphone'] = $keycell->cellphone;
                         $final[$ndx]['name'] = $keycell->firstname . " " . $keycell->surname;
                         $final[$ndx]['household'] = $ndx;
                     }
                 } else {
                     $final[$ndx]['cellphone'] = $thisdat['cellphone'];
                     $final[$ndx]['name'] = $thisdat['name'];
                     $final[$ndx]['household'] = $ndx;
                 }
             } else {
                 $dummy['cellphone'] = $thisdat['cellphone'];
                 $dummy['name'] = $thisdat['name'];
                 $dummy['household'] = $ndx;
                 $final[] = $dummy;
             }
         }
         if ($soc->sms_provider == "bulksms") {
             if (count($final) > SMSfunctions::BS_get_credits($soc->sms_username, $soc->sms_password)) {
                 return Redirect::back()->withInput()->withErrors("Insufficient Bulk SMS credits to send SMS");
             }
             $url = 'http://community.bulksms.com/eapi/submission/send_sms/2/2.0';
             $port = 80;
         } elseif ($soc->sms_provider == "smsfactory") {
             if (count($final) > SMSfunctions::SF_checkCredits($soc->sms_username, $soc->sms_password)) {
                 return Redirect::back()->withInput()->withErrors("Insufficient SMS Factory credits to send SMS");
             }
         }
         $seven_bit_msg = Input::get('message') . " (From " . substr($soc->society, 0, 1) . "MC)";
         foreach ($final as $sms) {
             if ($soc->sms_provider == "bulksms") {
                 $transient_errors = array(40 => 1);
                 $msisdn = "+27" . substr($sms['cellphone'], 1);
                 $post_body = SMSfunctions::BS_seven_bit_sms($soc->sms_username, $soc->sms_password, $seven_bit_msg, $msisdn);
             }
             $dum2['name'] = $sms['name'];
             $dum2['household'] = $sms['household'];
             if (SMSfunctions::checkcell($sms['cellphone'])) {
                 if ($soc->sms_provider == "bulksms") {
                     $smsresult = SMSfunctions::BS_send_message($post_body, $url, $port);
                 } elseif ($soc->sms_provider == "smsfactory") {
                     $smsresult = SMSfunctions::SF_sendSms($soc->sms_username, $soc->sms_password, $sms['cellphone'], $seven_bit_msg);
                 }
                 $dum2['address'] = $sms['cellphone'];
             } else {
                 if ($sms['cellphone'] == "") {
                     $dum2['address'] = "No cell number provided.";
                 } else {
                     $dum2['address'] = "Invalid cell number: " . $sms['cellphone'] . ".";
                 }
             }
             $results[] = $dum2;
         }
         $data['results'] = $results;
     }
     $data['type'] = $type;
     $data['results'] = $results;
     return View::make('messages.results', $data);
 }
 public function anyIndex()
 {
     return Group::with(['users'])->get()->toJson();
 }
Esempio n. 6
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $societies = Society::where('group_birthdays', '<>', 0)->select('group_birthdays', 'id', 'email', 'society')->get();
     foreach ($societies as $soc) {
         // Birthdays
         $thisyr = date("Y");
         $mon = strval(date('m-d', strtotime("next Monday")));
         $tue = strval(date('m-d', strtotime("next Monday") + 86400));
         $wed = strval(date('m-d', strtotime("next Monday") + 172800));
         $thu = strval(date('m-d', strtotime("next Monday") + 259200));
         $fri = strval(date('m-d', strtotime("next Monday") + 345600));
         $sat = strval(date('m-d', strtotime("next Monday") + 432000));
         $sun = strval(date('m-d', strtotime("next Monday") + 518400));
         $msg = "Birthdays for the week: (starting " . $thisyr . "-" . $mon . ")<br><br>";
         $days = array($mon, $tue, $wed, $thu, $fri, $sat, $sun);
         //DB::enableQueryLog();
         $birthdays = Individual::join('households', 'household_id', '=', 'households.id')->where('households.society_id', '=', $soc->id)->select('individuals.id', 'homephone', 'householdcell', 'cellphone', 'firstname', 'surname', DB::raw('substr(birthdate, 6, 5) as bd'))->wherein(DB::raw('substr(birthdate, 6, 5)'), $days)->orderBy(DB::raw('substr(birthdate, 6, 5)'))->get();
         //Log::debug(DB::getQueryLog());
         foreach ($birthdays as $bday) {
             $msg = $msg . date("D d M", strtotime($thisyr . "-" . $bday->bd)) . " " . $bday->firstname . " " . $bday->surname . ":";
             if ($bday->cellphone) {
                 $msg = $msg . " Cellphone: " . $bday->cellphone;
             }
             if ($bday->homephone) {
                 $msg = $msg . " Homephone: " . $bday->homephone;
             }
             if ($bday->householdcell and $bday->householdcell != $bday->id) {
                 $msg = $msg . " Household cellphone: " . self::gethcell($bday->householdcell);
             }
             $msg = $msg . "<br>";
             //Log::notice($bday->surname . ", " . $bday->firstname);
         }
         $anniversaries = Specialday::join('households', 'household_id', '=', 'households.id')->select('homephone', 'householdcell', 'addressee', 'household_id', 'anntype', 'details', DB::raw('substr(anniversarydate, 6, 5) as ad'))->wherein(DB::raw('substr(anniversarydate, 6, 5)'), $days)->orderBy(DB::raw('substr(anniversarydate, 6, 5)'))->get();
         $msg = $msg . "<br>" . "Anniversaries" . "<br><br>";
         foreach ($anniversaries as $ann) {
             $msg = $msg . date("D d M", strtotime($thisyr . "-" . $ann->ad)) . " (" . $ann->addressee . ". " . ucfirst($ann->anntype) . ": " . $ann->details . ")";
             if ($ann->homephone) {
                 $msg = $msg . " Homephone: " . $ann->homephone;
             }
             if ($ann->householdcell) {
                 $msg = $msg . " Household cellphone: " . self::gethcell($ann->householdcell);
             }
             $msg = $msg . "<br>";
         }
         $group = Group::with('individual')->find($soc->group_birthdays);
         foreach ($group->individual as $recip) {
             $fname = $recip->firstname;
             $name = $recip->firstname . " " . $recip->surname;
             $email = $recip->email;
             $subject = "Birthday email from " . $soc->society . " Methodist Church";
             Mail::queue('messages.message', array('msg' => "Good morning, " . $fname . " :)<br><br>" . $msg), function ($message) use($name, $email, $subject, $soc) {
                 $message->from($soc->email, $soc->society . " Methodist Church");
                 $message->to($email, $name);
                 $message->replyTo($email);
                 $message->subject($subject);
             });
         }
     }
 }
Esempio n. 7
0
 /**
  * Get full list of groups and basic information
  */
 public function index()
 {
     $g = Group::with('leaders')->with('tags')->get(['id', 'name', 'profile_pic', 'group_type'])->toArray();
     // dd($g);
     return $g;
 }
Esempio n. 8
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($society, $id)
 {
     if (Helpers::perm('admin', $society) or Helpers::perm('edit', $society)) {
         $data['group'] = Group::with(array('individual' => function ($query) {
             $query->wherePivot('deleted_at', null)->orderBy('surname', 'asc');
         }))->find($id);
         $data['individuals'] = Individual::socindiv($society)->get();
         $data['society'] = $society;
         $coords = Society::find($society);
         if ($data['group']->latitude == "0") {
             $data['deflat'] = $coords->latitude;
             $data['deflon'] = $coords->longitude;
         }
         $data['history'] = Group::with('individual')->find($id);
         $data['members'] = Individual::socindiv($society)->get();
         $data['contact'] = Individual::find($data['group']->contact);
         $daysofweek = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday');
         $data['meeting'] = $daysofweek[-1 + $data['group']->meeting];
         return View::make('groups.edit', $data);
     } else {
         return View::make("shared.unauthorised");
     }
 }