Ejemplo n.º 1
0
function getFormElementsHtmlAsArray($moduleCompId, $userId, &$jsValidationFunctions, &$containsFileUploadFields)
{
    /// Check if the user has already registered to this form,
    /// If yes, load default values for each field.
    /// We'll keep this as an associative array, relating element id to value
    $containsFileUploadFields = false;
    $formValues = array();
    if (verifyUserRegistered($moduleCompId, $userId)) {
        $dataQuery = 'SELECT `form_elementid`, `form_elementdata` FROM `form_elementdata` WHERE ' . "`page_modulecomponentid` = '{$moduleCompId}' AND `user_id` = '{$userId}'";
        $dataResult = mysql_query($dataQuery);
        if (!$dataResult) {
            displayerror('E35 : Invalid query: ' . mysql_error());
            return false;
        }
        while ($dataRow = mysql_fetch_assoc($dataResult)) {
            $formValues[$dataRow['form_elementid']] = $dataRow['form_elementdata'];
        }
    } else {
        $dataQuery = 'SELECT `form_elementid`, `form_elementdefaultvalue` FROM `form_elementdesc` WHERE ' . "`page_modulecomponentid` = '{$moduleCompId}'";
        $dataResult = mysql_query($dataQuery);
        if (!$dataResult) {
            displayerror('E132 : Invalid query: ' . mysql_error());
            return false;
        }
        while ($dataRow = mysql_fetch_assoc($dataResult)) {
            $formValues[$dataRow['form_elementid']] = $dataRow['form_elementdefaultvalue'];
        }
    }
    $elementQuery = 'SELECT `form_elementid`, `form_elementtype` FROM `form_elementdesc` WHERE ' . "`page_modulecomponentid` ='{$moduleCompId}' ORDER BY `form_elementrank`";
    $elementResult = mysql_query($elementQuery);
    $formElements = array();
    $jsValidationFunctions = array();
    while ($elementRow = mysql_fetch_row($elementResult)) {
        $jsOutput = '';
        if ($elementRow[1] == 'file') {
            $containsFileUploadFields = true;
        }
        $formElements[] = getFormElementInputField($moduleCompId, $elementRow[0], isset($formValues[$elementRow[0]]) ? $formValues[$elementRow[0]] : '', $jsOutput);
        if ($jsOutput != '') {
            $jsValidationFunctions[] = $jsOutput;
        }
    }
    return $formElements;
}
Ejemplo n.º 2
0
 public function actionEditregistrants()
 {
     /**
      * After view registrants completes, generateFormDataRow() will be used here also
      * then manually prepend the "delete" button and "edit" button columns
      *
      * After  generateFormDataTable() completes, move the code to generate the top header row (with the sort
      * 			by this column images) to a new function and call it here also and manually prepened two <th>s of
      * 			delete and edit
      *
      * The delete button should point to a subaction through get vars
      *
      * Clicking edit button, should do something like edit in 2nd form in "editform" does with a twist :
      *	to generate the edit form simply call generateRegistrationForm($moduleCompId,$userId,$action=)
      *  with action ./+editregistrants&subaction=editregistrant&useremail=<useremail>
      *
      * and when submitted call submitRegistrationForm()
      */
     global $sourceFolder, $moduleFolder;
     if (isset($_GET['subaction']) && isset($_GET['useremail'])) {
         if ($_GET['subaction'] == 'edit') {
             if (isset($_POST['submitreg_form_' . $this->moduleComponentId])) {
                 submitRegistrationForm($this->moduleComponentId, getUserIdFromEmail(escape($_GET['useremail'])), true, true);
             }
             return '<a href="./+editregistrants">&laquo; Back</a><br />' . generateRegistrationForm($this->moduleComponentId, $this->userId, './+editregistrants&subaction=edit&useremail=' . escape($_GET['useremail']), true) . '<br /><a href="./+editregistrants">&laquo; Back</a><br />';
         } elseif ($_GET['subaction'] == 'delete') {
             if ($_GET['useremail'] == "Anonymous") {
                 $userIdTemp = escape($_GET['registrantid']);
             } else {
                 $userIdTemp = getUserIdFromEmail(escape($_GET['useremail']));
             }
             if (!unregisterUser($this->moduleComponentId, $userIdTemp)) {
                 displayerror('Error! User with the given e-mail ' . escape($_GET['useremail']) . ' was not found.');
             }
         }
     } elseif (isset($_GET['subaction']) && $_GET['subaction'] == 'getsuggestions' && isset($_GET['forwhat'])) {
         echo $this->getUnregisteredUsersFromPattern(escape($_GET['forwhat']));
         disconnect();
         exit;
     } elseif (isset($_POST['btnAddUserToForm']) && isset($_POST['useremail'])) {
         $hyphenPos = strpos($_POST['useremail'], '-');
         if ($hyphenPos >= 0) {
             $userEmail = escape(trim(substr($_POST['useremail'], 0, $hyphenPos - 1)));
         } else {
             $userEmail = escape($_POST['useremail']);
         }
         $targetUserId = getUserIdFromEmail($userEmail);
         if ($targetUserId > 0) {
             if (verifyUserRegistered($this->moduleComponentId, $targetUserId)) {
                 displayerror('The given user is already registered to this form.');
             } else {
                 registerUser($this->moduleComponentId, $targetUserId);
             }
         } else {
             displayerror('A user registered with the e-mail ID you entered was not found.');
         }
     } elseif (isset($_POST['btnEmptyRegistrants'])) {
         $registeredUsers = form::getRegisteredUserArray($this->moduleComponentId);
         $registeredUserCount = count($registeredUsers);
         for ($i = 0; $i < $registeredUserCount; $i++) {
             unregisterUser($this->moduleComponentId, $registeredUsers[$i], true);
         }
         displayinfo('All registrations to this form have been deleted.');
     }
     $sortField = 'registrationdate';
     /// Default Values
     $sortOrder = 'asc';
     if (isset($_GET['sortfield'])) {
         $sortField = escape($_GET['sortfield']);
     }
     if (isset($_GET['sortorder']) && ($_GET['sortorder'] == 'asc' || $_GET['sortorder'] == 'desc')) {
         $sortOrder = escape($_GET['sortorder']);
     }
     global $ICONS;
     $html = generateFormDataTable($this->moduleComponentId, $sortField, $sortOrder, 'editregistrants');
     return "<fieldset><legend>{$ICONS['Form Registrants']['small']}Edit Form Registrants</legend>{$html}</fieldset>";
 }
Ejemplo n.º 3
0
/** Unegister a user in form_regdata table and remove his data from elementdata table*/
function unregisterUser($moduleCompId, $userId, $silentOnSuccess = false)
{
    if (verifyUserRegistered($moduleCompId, $userId)) {
        $unregisteruser_query = "DELETE FROM `form_regdata` WHERE `user_id` = '{$userId}' AND `page_modulecomponentid` = '{$moduleCompId}'";
        $unregisteruser_result = mysql_query($unregisteruser_query);
        /// Remove any files uploaded by the user
        $fileFieldQuery = 'SELECT `form_elementdata` FROM `form_elementdata`, `form_elementdesc` WHERE ' . "`form_elementdata`.`page_modulecomponentid` = '{$moduleCompId}' AND `form_elementtype` = 'file' AND " . "`form_elementdata`.`user_id` = '{$userId}' AND `form_elementdesc`.`page_modulecomponentid` = `form_elementdata`.`page_modulecomponentid` AND " . "`form_elementdata`.`form_elementid` = `form_elementdesc`.`form_elementid`";
        $fileFieldResult = mysql_query($fileFieldQuery);
        global $sourceFolder;
        require_once "{$sourceFolder}/upload.lib.php";
        while ($fileFieldRow = mysql_fetch_row($fileFieldResult)) {
            deleteFile($moduleCompId, 'form', $fileFieldRow[0]);
        }
        $deleteelementdata_query = "DELETE FROM `form_elementdata` WHERE `user_id` = '{$userId}' AND `page_modulecomponentid` = '{$moduleCompId}' ";
        $deleteelementdata_result = mysql_query($deleteelementdata_query);
        if ($deleteelementdata_result) {
            global $sourceFolder;
            require_once $sourceFolder . "/group.lib.php";
            $groupId = getGroupIdFromFormId($moduleCompId);
            if ($groupId != false) {
                if (removeUserFromGroupId($groupId, $userId)) {
                    if (!$silentOnSuccess) {
                        displayinfo("User successfully unregistered");
                    }
                    return true;
                } else {
                    displayerror("Unable to unregister user from group.");
                    return false;
                }
            } else {
                if (!$silentOnSuccess) {
                    displayinfo("User successfully unregistered");
                }
                return true;
            }
        } else {
            displayerror("Error in unregistering user.");
            return false;
        }
    } else {
        displaywarning("User not registered!");
        return false;
    }
}
Ejemplo n.º 4
0
/**
 *
 * @param $moduleCompId
 * @param $userId
 */
function getFormElementsHtmlAsArrayForView($moduleCompId, $userId)
{
    /// Check if the user has already registered to this form,
    /// If yes, load default values for each field.
    /// We'll keep this as an associative array, relating element id to value
    $formValues = array();
    if (verifyUserRegistered($moduleCompId, $userId)) {
        $dataQuery = 'SELECT `form_elementid`, `form_elementdata` FROM `form_elementdata` WHERE ' . "`page_modulecomponentid` = '{$moduleCompId}' AND `user_id` = '{$userId}'";
        $dataResult = mysql_query($dataQuery);
        if (!$dataResult) {
            displayerror('E35 : Invalid query: ' . mysql_error());
            return false;
        }
        while ($dataRow = mysql_fetch_assoc($dataResult)) {
            $formValues[$dataRow['form_elementid']] = $dataRow['form_elementdata'];
        }
    } else {
        $dataQuery = 'SELECT `form_elementid`, `form_elementdefaultvalue` FROM `form_elementdesc` WHERE ' . "`page_modulecomponentid` = '{$moduleCompId}'";
        $dataResult = mysql_query($dataQuery);
        if (!$dataResult) {
            displayerror('E132 : Invalid query: ' . mysql_error());
            return false;
        }
        while ($dataRow = mysql_fetch_assoc($dataResult)) {
            $formValues[$dataRow['form_elementid']] = $dataRow['form_elementdefaultvalue'];
        }
    }
    $elementQuery = 'SELECT `form_elementid`, `form_elementtype`, `form_elementdisplaytext` FROM `form_elementdesc` WHERE ' . "`page_modulecomponentid` ='{$moduleCompId}' ORDER BY `form_elementrank`";
    $elementResult = mysql_query($elementQuery);
    $formElements = array();
    while ($elementRow = mysql_fetch_assoc($elementResult)) {
        if ($elementRow['form_elementtype'] == 'file') {
            global $urlRequestRoot;
            $fileLink = $formValues[$elementRow['form_elementid']];
            if ($formValues[$elementRow['form_elementid']] != '') {
                if ($moduleCompId != '0') {
                    $fileUrl = $urlRequestRoot . getPagePathFromModule('form', $moduleCompId) . '/' . $formValues[$elementRow['form_elementid']];
                    $fileLink = "<a href='" . $fileUrl . "'>" . $formValues[$elementRow['form_elementid']] . "</a>";
                }
            }
            $htmlOutput = '<td>' . $elementRow['form_elementdisplaytext'];
            $htmlOutput .= '</td><td>' . $fileLink . '</td>';
            $formElements[] = $htmlOutput;
        } elseif ($elementRow['form_elementtype'] != 'password') {
            $htmlOutput = '<td>' . $elementRow['form_elementdisplaytext'];
            $htmlOutput .= '</td><td>' . (isset($formValues[$elementRow['form_elementid']]) ? $formValues[$elementRow['form_elementid']] : '') . '</td>';
            $formElements[] = $htmlOutput;
        }
    }
    return $formElements;
}