Beispiel #1
0
 public function deleteData($userId)
 {
     // USER INFO
     foreach (Opts::I()->hw2cf_fields["user"] as $field) {
         if ($field instanceof Field) {
             delete_user_meta($userId, $field->getFullAlias());
         }
     }
     delete_user_meta($userId, 'hw2cf_user_sign_date');
     delete_user_meta($userId, 'hw2cf_user_saved');
     // PROPONENT
     foreach (Opts::I()->hw2cf_fields["prop"] as $field) {
         if ($field instanceof Field) {
             delete_user_meta($userId, $field->getFullAlias());
         }
     }
 }
Beispiel #2
0
            });
        </script>

        <br>
        <br>
        <br>
        <h2> <?php 
echo Opts::I()->hw2cf_name;
?>
 Fields </h2>

        <?php 
$formView->printFields("prop");
// DO NOT SHOW ADMIN SIGNATURE ON USER SESSION
if ($formView->isAdmin()) {
    $field = Opts::I()->getField("prop", "signature");
    ?>
            <fieldset>
                <p>
                    <label for="<?php 
    echo $field->getFullAlias();
    ?>
"><?php 
    echo $field->title;
    echo $field->isRequired ? "*" : "";
    ?>
</label>
                    <input name="<?php 
    echo $field->getFullAlias();
    ?>
" value="<?php 
 public function init()
 {
     $this->uId = intval(filter_input(INPUT_GET, "user"));
     if (!$this->uId) {
         $user = get_user_by('login', get_query_var('friendly'));
         if ($user) {
             $this->uId = $user->ID;
         }
     }
     $userRole = FormHelper::getUserFirstRole();
     $this->isAdmin = $userRole == "administrator";
     $this->data = $this->model->loadData($this->uId);
     $user_info = get_userdata($this->uId);
     switch (filter_input(INPUT_POST, 'action')) {
         case 'Save':
             if (!$this->isAdmin) {
                 $hasSaved = FormHelper::getDataVal($this->data, "hw2cf_user_saved");
                 if (!empty($hasSaved)) {
                     // hey user, are you trying to re-save?
                     echo "Cannot resend post data!";
                 } else {
                     $this->model->storeData($this->uId, $_POST, $this->isAdmin);
                     // reload data after save
                     $this->data = $this->model->loadData($this->uId);
                     $message = "The user " . FormHelper::getUserFormName($this->data) . " has compiled the agreement form <br>" . "Use this <a href='" . bloginfo("url") . '/' . Opts::I()->hw2cf_page_alias . "/?user="******"'>link</a> for direct access<br>";
                     $email = Opts::I()->hw2cf_email;
                     $headers = array('Content-Type: text/html; charset=UTF-8', 'From: ' . Opts::I()->company_name . ' <' . $email . '>');
                     $roleName = FormHelper::getRoleDisplayName($userRole);
                     $subject = "< {$user_info->user_email} > New {$roleName} has signed agreement";
                     wp_mail($email, $subject, $message, $headers);
                 }
             } else {
                 $this->model->storeData($this->uId, $_POST, $this->isAdmin);
                 // reload data after save
                 $this->data = $this->model->loadData($this->uId);
             }
             break;
         case 'Generate PDF':
             $template = new PdfTemplate($this->data);
             $uRole = FormHelper::getUserFirstRole($this->uId);
             $html = $template->getTemplate();
             /*
              // test document with html
              @unlink(PATH_HW2CF_PLG . "sample.html");
              $htmlFile = fopen(PATH_HW2CF_PLG . "sample.html", "w") or die("Unable to open file!");
              fwrite($htmlFile, $html);
              fclose($htmlFile);
             */
             $dompdf = new \DOMPDF();
             $dompdf->load_html($html);
             $dompdf->render();
             $roleName = FormHelper::getRoleDisplayName($uRole);
             $uName = FormHelper::getUserFormName($this->data);
             $email = Opts::I()->hw2cf_email;
             $fileName = FormHelper::sanitizeFileName("MDA_{$uName}.pdf");
             // REPLACE
             //@unlink(PATH_HW2CF_PLG . $fileName);
             //@unlink(PATH_HW2CF_PLG . "user-sign.png");
             //@unlink(PATH_HW2CF_PLG . "prop-sign.png");
             $pdfFile = fopen(PATH_HW2CF_PLG . $fileName, "w") or die("Unable to open file!");
             fwrite($pdfFile, $dompdf->output());
             fclose($pdfFile);
             $headers = array('Content-Type: text/html; charset=UTF-8', 'From: ' . Opts::I()->hw2cf_company_name . ' <' . $email . '>');
             $message = "New Contract has been signed." . "<br>Attached is a PDF" . "<br><br> {$fileName}" . "<br>Generated pdf related to <a href='" . bloginfo("url") . '/' . Opts::I()->hw2cf_page_alias . "/?user="******"'>this</a> agreement form ";
             $subject = "< {$user_info->user_email} > Generated PDF for new {$roleName} ( {$uName} )";
             wp_mail($email, $subject, $message, $headers, PATH_HW2CF_PLG . $fileName);
             // KEEP CLEAN
             unlink(PATH_HW2CF_PLG . $fileName);
             unlink(PATH_HW2CF_PLG . "user-sign.png");
             unlink(PATH_HW2CF_PLG . "prop-sign.png");
             break;
         case "Delete data":
             $this->model->deleteData($this->uId);
             // reload data after delete
             $this->data = $this->model->loadData($this->uId);
             break;
         default:
             //invalid action
             break;
     }
     $allowed_roles = array("subscriber");
     if (FormHelper::userIdExists($this->uId) && ($this->isAdmin || is_user_logged_in() && in_array($userRole, $allowed_roles) && get_current_user_id() == $this->uId)) {
         // then show the form
         echo $this->view->getRender($this->data);
     } else {
         echo 'What are you doing here?';
     }
 }
 public function loadData()
 {
     return Opts::I()->loadFromDb();
 }
Beispiel #5
0
 public function printFields($type)
 {
     foreach (Opts::I()->hw2cf_fields[$type] as $field) {
         $this->printField($field);
     }
 }