Пример #1
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);
 }
Пример #2
0
 public function birthdays($society)
 {
     $soc = Society::find($society);
     $houses = Household::with('individual')->where('society_id', '=', $society)->get();
     foreach ($houses as $house) {
         foreach ($house->individual as $indiv) {
             if ($indiv->memberstatus != 'non-member' and $indiv->birthdate != '0000-00-00' and $indiv->birthdate != '' and !is_null($indiv->birthdate)) {
                 $mth = intval(substr($indiv->birthdate, 5, 2));
                 $day = intval(substr($indiv->birthdate, 8, 2));
                 $dum = utf8_decode($indiv->firstname) . " " . utf8_decode($indiv->surname);
                 if ($indiv->cellphone != '') {
                     $dum = $dum . " (Cellphone: " . $indiv->cellphone . ")";
                 }
                 if ($house->homephone != '') {
                     $dum = $dum . " (Home phone: " . $house->homephone . ")";
                 }
                 if ($house->householdcell != 0 and $house->householdcell != $indiv->id) {
                     $dum = $dum . " (Additional cell number: " . $this->gethcell($house->householdcell) . ")";
                 }
                 $indivs[$mth][$day][] = $dum;
             }
         }
     }
     ksort($indivs);
     $pdf = new Fpdf();
     foreach ($indivs as $key => $mth) {
         ksort($mth);
         $pdf->AddPage('P');
         $pdf->SetAutoPageBreak(0, 0);
         $pdf->SetFont('Arial', 'B', 12);
         $monthName = date("F", mktime(null, null, null, $key));
         $pdf->text(10, 10, $soc->society . " Birthdays: " . $monthName);
         $pdf->SetFont('Arial', '', 9);
         $yy = 20;
         foreach ($mth as $dd => $day) {
             foreach ($day as $bd) {
                 $pdf->text(10, $yy, $dd . " " . $bd);
                 $yy = $yy + 4;
             }
         }
     }
     $pdf->Output();
 }