Beispiel #1
0
 /**
  * execute
  *
  * @param \Form\Form $form
  */
 public function update($form)
 {
     $config = \Tk\Config::getInstance();
     $data = $form->getObject();
     /* @var $field \Form\Field\Interface */
     foreach ($form->getFieldList() as $field) {
         if ($field->isRequired() && !$field->getValue() && $field->getName() != 'valid') {
             $field->addError('Please enter some valid data.');
         }
     }
     if ($form->hasErrors()) {
         return;
     }
     $message = '<table border="0" cellpadding="2" cellspacing="0" >';
     $message .= '<tr><th> Field </th><th> Value </th></tr>';
     $skip = array('__submitId', 'valid', 'send');
     /* @var $field \Form\Field\Interface */
     foreach ($form->getFieldList() as $field) {
         if (in_array($field->getName(), $skip)) {
             continue;
         }
         if ($field->getValue()) {
             $message .= '<tr><th class="label"> ' . $field->getLabel() . ': </th><td class="value"> ' . nl2br(htmlentities($field->getValue())) . ' </td></tr>';
         }
     }
     $message .= '</table>';
     $mail = new \Tk\Mail\Message();
     $mail->addTo($this->getConfig()->get('system.site.email'), $this->getConfig()->get('system.site.title'));
     $mail->setFrom($form->getFieldValue('email'), $form->getFieldValue('name'));
     $mail->setSubject('Contact Us Form Sent From ' . $this->getRequest()->getServer('HTTP_HOST'));
     $mail->setBody($mail->createHtmlTemplate($message));
     $mail->send();
     \Mod\Notice::addSuccess('Message Submited Successfully. Thank You!');
     $this->getUri()->redirect();
 }
Beispiel #2
0
 /**
  * Get an instance of this object
  *
  * @param array $data
  * @return \Ext\LtiSession
  */
 static function getInstance($data = null)
 {
     if (self::$instance == null) {
         if ($data) {
             \Tk\Config::getInstance()->getSession()->set('res.lti.session.data', $data);
         }
         self::$instance = new self(\Tk\Config::getInstance()->getSession()->get('res.lti.session.data'));
     }
     return self::$instance;
 }
Beispiel #3
0
 /**
  *
  */
 public function doSendCert()
 {
     $filter = $this->table->getFilterValues();
     $image = $this->setup->getPdfBgImageUrl()->toString();
     $now = \Tk\Date::create();
     $dateFrom = $filter['dateFrom']->floor()->toString(\Tk\Date::LONG_DATE);
     $dateTo = $filter['dateTo']->ceil()->toString(\Tk\Date::LONG_DATE);
     $tpl = $this->setup->pdfContent;
     $course = $this->term->getCourse();
     $list = $this->getList();
     $i = 0;
     foreach ($list as $obj) {
         //vd($obj);
         $dompdf = $this->makeCert($obj, $dateFrom, $dateTo, $image, $tpl);
         $message = \Tk\Config::getInstance()->createMailTplMessage(\Ext\Mail::getThemeMailTemplate());
         $message->setSubject($this->setup->emailSubject);
         $from = \Tk\Config::getInstance()->getSiteEmail();
         if ($course) {
             $from = $course->getEmail();
         }
         $message->setFrom($from);
         $message->set('content', $this->setup->emailContent);
         $message->set('termId', $this->term->getId());
         $message->set('date', $now->toString(\Tk\Date::LONG_DATE));
         $message->set('year', $now->toString('Y'));
         $message->set('dateFrom', $dateFrom);
         $message->set('dateTo', $dateTo);
         $message->set('courseId', $course->id);
         $message->set('name', $obj->name);
         $message->set('email', $obj->email);
         $message->set('companyId', $obj->id);
         $message->set('totalUnits', $obj->totalUnits);
         $message->set('totalPlaces', $obj->totalPlaces);
         $message->set('sig', \Tk\Config::getInstance()->get('mail.sig'));
         if ($course->emailSigniture) {
             $message->set('sig', $course->emailSigniture);
         }
         $message->addTo($obj->email);
         $message->addStringAttachment($dompdf->output(), 'Certificate_' . $now->toString('Y') . '.pdf');
         if (\Ext\Mail::send($message)) {
             $i++;
         }
     }
     \Mod\Notice::addSuccess($i . ' Certificates sent successfully.');
     $this->getUri()->delete('sendCert')->redirect();
 }
Beispiel #4
0
 /**
  * Get the response from an HTTP POST request.
  *
  * @param string $url URL to send request to
  * @param array $params Associative array of parameter values to be passed
  * @param string $header Values to include in the request header (optional, default is none)
  * @return string response contents, empty if the request was not successfull
  */
 private function do_post_request($url, $params, $header = NULL)
 {
     $ok = FALSE;
     if (is_array($params)) {
         $data = http_build_query($params);
     } else {
         $data = $params;
     }
     $this->ext_request = $data;
     // Try using curl if available
     if (function_exists('curl_init')) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         if (!empty($header)) {
             $headers = explode("\n", $header);
             curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
         }
         curl_setopt($ch, CURLOPT_POST, TRUE);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
         tklog('PROXY: ' . \Tk\Config::getInstance()->get('system.site.proxy'));
         if (\Tk\Config::getInstance()->get('system.site.proxy')) {
             tklog('PROXY: ' . \Tk\Config::getInstance()->get('system.site.proxy'));
             curl_setopt($ch, CURLOPT_PROXY, \Tk\Config::getInstance()->get('system.site.proxy'));
         }
         $resp = curl_exec($ch);
         $ok = $resp !== FALSE;
         curl_close($ch);
     }
     // Try using fopen if curl was not available or did not work (could have been an SSL certificate issue)
     if (!$ok) {
         $opts = array('method' => 'POST', 'content' => $data);
         if (!empty($header)) {
             $opts['header'] = $header;
         }
         $ctx = stream_context_create(array('http' => $opts));
         $fp = @fopen($url, 'rb', false, $ctx);
         if ($fp) {
             $resp = @stream_get_contents($fp);
             $ok = $resp !== FALSE;
         }
     }
     if ($ok) {
         $response = $resp;
     } else {
         $response = '';
     }
     return $response;
 }