function getDBTableUsage($surveyid)
{
    Yii::app()->loadHelper('admin/activate');
    $arrCols = activateSurvey($surveyid, $surveyid, 'admin.php', true);
    $length = 1;
    foreach ($arrCols['fields'] as $col) {
        switch ($col[0]) {
            case 'C':
                $length = $length + $col[1] * 3 + 1;
                break;
            case 'X':
            case 'B':
                $length = $length + 12;
                break;
            case 'D':
                $length = $length + 3;
                break;
            case 'T':
            case 'TS':
            case 'N':
                $length = $length + 8;
                break;
            case 'L':
                $legth++;
                break;
            case 'I':
            case 'I4':
            case 'F':
                $length = $length + 4;
                break;
            case 'I1':
                $length = $length + 1;
                break;
            case 'I2':
                $length = $length + 2;
                break;
            case 'I8':
                $length = $length + 8;
                break;
        }
    }
    if ($arrCols['dbtype'] == 'mysql' || $arrCols['dbtype'] == 'mysqli') {
        if ($arrCols['dbengine'] == 'myISAM') {
            $hard_limit = 4096;
        } elseif ($arrCols['dbengine'] == "InnoDB") {
            $hard_limit = 1000;
        } else {
            return false;
        }
        $size_limit = 65535;
    } elseif ($arrCols['dbtype'] == 'postgre') {
        $hard_limit = 1600;
        $size_limit = 0;
    } elseif ($arrCols['dbtype'] == 'mssql' || $arrCols['dbtype'] == 'dblib') {
        $hard_limit = 1024;
        $size_limit = 0;
    } else {
        return false;
    }
    $columns_used = count($arrCols['fields']);
    return array('dbtype' => $arrCols['dbtype'], 'column' => array($columns_used, $hard_limit), 'size' => array($length, $size_limit));
}
示例#2
0
function importSurveyFile($sFullFilepath, $bTranslateLinksFields, $sNewSurveyName = NULL, $DestSurveyID = NULL)
{
    $aPathInfo = pathinfo($sFullFilepath);
    if (isset($aPathInfo['extension'])) {
        $sExtension = $aPathInfo['extension'];
    } else {
        $sExtension = "";
    }
    if (isset($sExtension) && strtolower($sExtension) == 'csv') {
        return CSVImportSurvey($sFullFilepath, $DestSurveyID, $bTranslateLinksFields);
    } elseif (isset($sExtension) && strtolower($sExtension) == 'lss') {
        return XMLImportSurvey($sFullFilepath, null, $sNewSurveyName, $DestSurveyID, $bTranslateLinksFields);
    } elseif (isset($sExtension) && strtolower($sExtension) == 'txt') {
        return TSVImportSurvey($sFullFilepath);
    } elseif (isset($sExtension) && strtolower($sExtension) == 'lsa') {
        Yii::import("application.libraries.admin.pclzip.pclzip", true);
        $pclzip = new PclZip(array('p_zipname' => $sFullFilepath));
        $aFiles = $pclzip->listContent();
        if ($pclzip->extract(PCLZIP_OPT_PATH, Yii::app()->getConfig('tempdir') . DIRECTORY_SEPARATOR, PCLZIP_OPT_BY_EREG, '/(lss|lsr|lsi|lst)$/') == 0) {
            unset($pclzip);
        }
        // Step 1 - import the LSS file and activate the survey
        foreach ($aFiles as $aFile) {
            if (pathinfo($aFile['filename'], PATHINFO_EXTENSION) == 'lss') {
                //Import the LSS file
                $aImportResults = XMLImportSurvey(Yii::app()->getConfig('tempdir') . DIRECTORY_SEPARATOR . $aFile['filename'], null, null, null, true);
                // Activate the survey
                Yii::app()->loadHelper("admin/activate");
                $activateoutput = activateSurvey($aImportResults['newsid']);
                unlink(Yii::app()->getConfig('tempdir') . DIRECTORY_SEPARATOR . $aFile['filename']);
                break;
            }
        }
        // Step 2 - import the responses file
        foreach ($aFiles as $aFile) {
            if (pathinfo($aFile['filename'], PATHINFO_EXTENSION) == 'lsr') {
                //Import the LSS file
                $aResponseImportResults = XMLImportResponses(Yii::app()->getConfig('tempdir') . DIRECTORY_SEPARATOR . $aFile['filename'], $aImportResults['newsid'], $aImportResults['FieldReMap']);
                $aImportResults = array_merge($aResponseImportResults, $aImportResults);
                unlink(Yii::app()->getConfig('tempdir') . DIRECTORY_SEPARATOR . $aFile['filename']);
                break;
            }
        }
        // Step 3 - import the tokens file - if exists
        foreach ($aFiles as $aFile) {
            if (pathinfo($aFile['filename'], PATHINFO_EXTENSION) == 'lst') {
                Yii::app()->loadHelper("admin/token");
                if (createTokenTable($aImportResults['newsid'])) {
                    $aTokenCreateResults = array('tokentablecreated' => true);
                }
                $aImportResults = array_merge($aTokenCreateResults, $aImportResults);
                $aTokenImportResults = XMLImportTokens(Yii::app()->getConfig('tempdir') . DIRECTORY_SEPARATOR . $aFile['filename'], $aImportResults['newsid']);
                $aImportResults = array_merge($aTokenImportResults, $aImportResults);
                unlink(Yii::app()->getConfig('tempdir') . DIRECTORY_SEPARATOR . $aFile['filename']);
                break;
            }
        }
        // Step 4 - import the timings file - if exists
        foreach ($aFiles as $aFile) {
            if (pathinfo($aFile['filename'], PATHINFO_EXTENSION) == 'lsi' && tableExists("survey_{$aImportResults['newsid']}_timings")) {
                $aTimingsImportResults = XMLImportTimings(Yii::app()->getConfig('tempdir') . DIRECTORY_SEPARATOR . $aFile['filename'], $aImportResults['newsid'], $aImportResults['FieldReMap']);
                $aImportResults = array_merge($aTimingsImportResults, $aImportResults);
                unlink(Yii::app()->getConfig('tempdir') . DIRECTORY_SEPARATOR . $aFile['filename']);
                break;
            }
        }
        return $aImportResults;
    } else {
        return null;
    }
}
示例#3
0
 /**
  * Function responsible to activate survey.
  *
  * @access public
  * @param int $iSurveyID
  * @return void
  */
 public function activate($iSurveyID)
 {
     if (!Permission::model()->hasSurveyPermission($iSurveyID, 'surveyactivation', 'update')) {
         die;
     }
     $iSurveyID = (int) $iSurveyID;
     $aData = array();
     $aData['aSurveysettings'] = getSurveyInfo($iSurveyID);
     $aData['surveyid'] = $iSurveyID;
     // Die if this is not possible
     if (!isset($aData['aSurveysettings']['active']) || $aData['aSurveysettings']['active'] == 'Y') {
         $this->getController()->error('Survey not active');
     }
     $qtypes = getQuestionTypeList('', 'array');
     Yii::app()->loadHelper("admin/activate");
     if (empty($_POST['ok'])) {
         if (isset($_GET['fixnumbering']) && $_GET['fixnumbering']) {
             fixNumbering($_GET['fixnumbering'], $iSurveyID);
         }
         // Check consistency for groups and questions
         $failedgroupcheck = checkGroup($iSurveyID);
         $failedcheck = checkQuestions($iSurveyID, $iSurveyID, $qtypes);
         $aData['failedcheck'] = $failedcheck;
         $aData['failedgroupcheck'] = $failedgroupcheck;
         $aData['aSurveysettings'] = getSurveyInfo($iSurveyID);
         $this->_renderWrappedTemplate('survey', 'activateSurvey_view', $aData);
     } else {
         $survey = Survey::model()->findByAttributes(array('sid' => $iSurveyID));
         if (!is_null($survey)) {
             $survey->anonymized = Yii::app()->request->getPost('anonymized');
             $survey->datestamp = Yii::app()->request->getPost('datestamp');
             $survey->ipaddr = Yii::app()->request->getPost('ipaddr');
             $survey->refurl = Yii::app()->request->getPost('refurl');
             $survey->savetimings = Yii::app()->request->getPost('savetimings');
             $survey->save();
             Survey::model()->resetCache();
             // Make sure the saved values will be picked up
         }
         $aResult = activateSurvey($iSurveyID);
         if (isset($aResult['error'])) {
             $aViewUrls['output'] = "<br />\n<div class='messagebox ui-corner-all'>\n" . "<div class='header ui-widget-header'>" . gT("Activate Survey") . " ({$iSurveyID})</div>\n";
             if ($aResult['error'] == 'surveytablecreation') {
                 $aViewUrls['output'] .= "<div class='warningheader'>" . gT("Survey table could not be created.") . "</div>\n";
             } else {
                 $aViewUrls['output'] .= "<div class='warningheader'>" . gT("Timings table could not be created.") . "</div>\n";
             }
             $aViewUrls['output'] .= "<p>" . gT("Database error!!") . "\n <font color='red'>" . "</font>\n" . "<pre>" . var_export($aResult['error'], true) . "</pre>\n\n                <a href='" . Yii::app()->getController()->createUrl("admin/survey/sa/view/surveyid/" . $iSurveyID) . "'>" . gT("Main Admin Screen") . "</a>\n</div>";
         } else {
             $aViewUrls['output'] = "<br />\n<div class='messagebox ui-corner-all'>\n" . "<div class='header ui-widget-header'>" . gT("Activate Survey") . " ({$iSurveyID})</div>\n" . "<div class='successheader'>" . gT("Survey has been activated. Results table has been successfully created.") . "</div><br /><br />\n";
             if (isset($aResult['warning'])) {
                 $aViewUrls['output'] .= "<div class='warningheader'>" . gT("The required directory for saving the uploaded files couldn't be created. Please check file premissions on the /upload/surveys directory.") . "</div>";
             }
             if ($survey->allowregister == 'Y') {
                 $aViewUrls['output'] .= gT("This survey allows public registration. A token table must also be created.") . "<br /><br />\n" . "<input type='submit' value='" . gT("Initialise tokens") . "' onclick=\"" . convertGETtoPOST(Yii::app()->getController()->createUrl("admin/tokens/sa/index/surveyid/" . $iSurveyID)) . "\" />\n";
             } else {
                 $aViewUrls['output'] .= gT("This survey is now active, and responses can be recorded.") . "<br /><br />\n" . "<strong>" . gT("Open-access mode") . ":</strong> " . gT("No invitation code is needed to complete the survey.") . "<br />" . gT("You can switch to the closed-access mode by initialising a token table with the button below.") . "<br /><br />\n" . "<input type='submit' value='" . gT("Switch to closed-access mode") . "' onclick=\"" . convertGETtoPOST(Yii::app()->getController()->createUrl("admin/tokens/sa/index/surveyid/" . $iSurveyID)) . "\" />\n" . "<input type='submit' value='" . gT("No, thanks.") . "' onclick=\"" . convertGETtoPOST(Yii::app()->getController()->createUrl("admin/survey/sa/view/surveyid/" . $iSurveyID)) . "\" />\n";
             }
             $aViewUrls['output'] .= "</div><br />&nbsp;\n";
         }
         $this->_renderWrappedTemplate('survey', $aViewUrls, $aData);
     }
 }
 /**
  * RPC Routine that launches a newly created survey.
  *
  * @access public
  * @param string $sSessionKey Auth credentials
  * @param int $iSurveyID The id of the survey to be activated
  * @return array The result of the activation
  */
 public function activate_survey($sSessionKey, $iSurveyID)
 {
     if ($this->_checkSessionKey($sSessionKey)) {
         $oSurvey = Survey::model()->findByPk($iSurveyID);
         if (is_null($oSurvey)) {
             return array('status' => 'Error: Invalid survey ID');
         }
         if (Permission::model()->hasSurveyPermission($iSurveyID, 'surveyactivation', 'update')) {
             Yii::app()->loadHelper('admin/activate');
             $aActivateResults = activateSurvey($iSurveyID);
             if (isset($aActivateResults['error'])) {
                 return array('status' => 'Error: ' . $aActivateResults['error']);
             } else {
                 return $aActivateResults;
             }
         } else {
             return array('status' => 'No permission');
         }
     } else {
         return array('status' => 'Invalid session key');
     }
 }
示例#5
0
        $activateoutput .= "<ul>\n";
        if (isset($failedcheck) && $failedcheck) {
            foreach ($failedcheck as $fc) {
                $activateoutput .= "<li> Question qid-{$fc[0]} (\"<a href='{$scriptname}?sid={$surveyid}&amp;gid={$fc['3']}&amp;qid={$fc['0']}'>{$fc[1]}</a>\"){$fc[2]}</li>\n";
            }
        }
        if (isset($failedgroupcheck) && $failedgroupcheck) {
            foreach ($failedgroupcheck as $fg) {
                $activateoutput .= "\t\t\t\t<li> Group gid-{$fg[0]} (\"<a href='{$scriptname}?sid={$surveyid}&amp;gid={$fg['0']}'>{$fg[1]}</a>\"){$fg[2]}</li>\n";
            }
        }
        $activateoutput .= "</ul>\n";
        $activateoutput .= $clang->gT("The survey cannot be activated until these problems have been resolved.") . "\n";
        $activateoutput .= "</div><br />&nbsp;\n";
        return;
    }
    $activateoutput .= "<br />\n<div class='messagebox ui-corner-all'>\n";
    $activateoutput .= "<div class='header ui-widget-header'>" . $clang->gT("Activate Survey") . " ({$surveyid})</div>\n";
    $activateoutput .= "<div class='warningheader'>\n";
    $activateoutput .= $clang->gT("Warning") . "<br />\n";
    $activateoutput .= $clang->gT("READ THIS CAREFULLY BEFORE PROCEEDING") . "\n";
    $activateoutput .= "\t</div>\n";
    $activateoutput .= $clang->gT("You should only activate a survey when you are absolutely certain that your survey setup is finished and will not need changing.") . "<br /><br />\n";
    $activateoutput .= $clang->gT("Once a survey is activated you can no longer:") . "<ul><li>" . $clang->gT("Add or delete groups") . "</li><li>" . $clang->gT("Add or delete questions") . "</li><li>" . $clang->gT("Add or delete subquestions or change their codes") . "</li></ul>\n";
    $activateoutput .= $clang->gT("However you can still:") . "<ul><li>" . $clang->gT("Edit your questions code/title/text and advanced options") . "</li><li>" . $clang->gT("Edit your group names or descriptions") . "</li><li>" . $clang->gT("Add, remove or edit answer options") . "</li><li>" . $clang->gT("Change survey name or description") . "</li></ul>\n";
    $activateoutput .= $clang->gT("Once data has been entered into this survey, if you want to add or remove groups or questions, you will need to deactivate this survey, which will move all data that has already been entered into a separate archived table.") . "<br /><br />\n";
    $activateoutput .= "\t<input type='submit' value=\"" . $clang->gT("Activate Survey") . "\" onclick=\"" . get2post("{$scriptname}?action=activate&amp;ok=Y&amp;sid={$_GET['sid']}") . "\" />\n";
    $activateoutput .= "</div><br />&nbsp;\n";
} else {
    $activateoutput = activateSurvey($postsid, $surveyid);
}
示例#6
0
 /**
  * function to activate surveys based on new activate.php 5771 2008-10-13 02:28:40Z jcleeland $
  *
  * @param unknown_type $surveyid
  * @return boolean
  */
 function activateSurvey($surveyid)
 {
     global $dbprefix, $connect, $clang, $databasetype, $databasetabletype;
     $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
     include "lsrc.config.php";
     include '../admin_functions.php';
     include '../activate_functions.php';
     $this->debugLsrc("wir sind in " . __FILE__ . " - " . __FUNCTION__ . " Line " . __LINE__ . ", OK ");
     $returnOutput = activateSurvey($surveyid, $surveyid, 'lsrc');
     $this->debugLsrc("wir sind in " . __FILE__ . " - " . __FUNCTION__ . " Line " . __LINE__ . ", {$returnOutput} ");
     return $returnOutput;
 }
示例#7
0
 /**
  * Function responsible to activate survey.
  *
  * @access public
  * @param int $iSurveyID
  * @return void
  */
 public function activate($iSurveyID)
 {
     if (!Permission::model()->hasSurveyPermission($iSurveyID, 'surveyactivation', 'update')) {
         die;
     }
     $iSurveyID = (int) $iSurveyID;
     $aData = array();
     $aData['sidemenu']['state'] = false;
     $aData['aSurveysettings'] = getSurveyInfo($iSurveyID);
     $aData['surveyid'] = $iSurveyID;
     $surveyinfo = Survey::model()->findByPk($iSurveyID)->surveyinfo;
     $aData['title_bar']['title'] = $surveyinfo['surveyls_title'] . "(" . gT("ID") . ":" . $iSurveyID . ")";
     // Die if this is not possible
     if (!isset($aData['aSurveysettings']['active']) || $aData['aSurveysettings']['active'] == 'Y') {
         $this->getController()->error('Survey not active');
     }
     $qtypes = getQuestionTypeList('', 'array');
     Yii::app()->loadHelper("admin/activate");
     if (empty($_POST['ok'])) {
         if (isset($_GET['fixnumbering']) && $_GET['fixnumbering']) {
             fixNumbering($_GET['fixnumbering'], $iSurveyID);
         }
         // Check consistency for groups and questions
         $failedgroupcheck = checkGroup($iSurveyID);
         $failedcheck = checkQuestions($iSurveyID, $iSurveyID, $qtypes);
         $aData['failedcheck'] = $failedcheck;
         $aData['failedgroupcheck'] = $failedgroupcheck;
         $aData['aSurveysettings'] = getSurveyInfo($iSurveyID);
         $this->_renderWrappedTemplate('survey', 'activateSurvey_view', $aData);
     } else {
         $survey = Survey::model()->findByAttributes(array('sid' => $iSurveyID));
         if (!is_null($survey)) {
             $survey->anonymized = Yii::app()->request->getPost('anonymized');
             $survey->datestamp = Yii::app()->request->getPost('datestamp');
             $survey->ipaddr = Yii::app()->request->getPost('ipaddr');
             $survey->refurl = Yii::app()->request->getPost('refurl');
             $survey->savetimings = Yii::app()->request->getPost('savetimings');
             $survey->save();
             Survey::model()->resetCache();
             // Make sure the saved values will be picked up
         }
         $aResult = activateSurvey($iSurveyID);
         if (isset($aResult['error'])) {
             $aViewUrls['output'] = "<br />\n<div class='messagebox ui-corner-all'>\n";
             if ($aResult['error'] == 'surveytablecreation') {
                 $aViewUrls['output'] .= "<div class='alert alert-warning' role='alert'>" . gT("Survey table could not be created.") . "</div>\n";
             } else {
                 $aViewUrls['output'] .= "<div class='alert alert-success' role='alert'>" . gT("Timings table could not be created.") . "</div>\n";
             }
             $aViewUrls['output'] .= "<strong class='text-warning'>" . gT("Database error!!") . "\n " . "\n" . "<pre>" . var_export($aResult['error'], true) . "</pre>\n\n                <a href='" . Yii::app()->getController()->createUrl("admin/survey/sa/view/surveyid/" . $iSurveyID) . "'>" . gT("Main Admin Screen") . "</a>\n</strong><br/>";
         } else {
             $warning = isset($aResult['warning']) ? true : false;
             $allowregister = $survey->allowregister == 'Y' ? true : false;
             $onclickAction = convertGETtoPOST(Yii::app()->getController()->createUrl("admin/tokens/sa/index/surveyid/" . $iSurveyID));
             $closedOnclickAction = convertGETtoPOST(Yii::app()->getController()->createUrl("admin/tokens/sa/index/surveyid/" . $iSurveyID));
             $noOnclickAction = convertGETtoPOST(Yii::app()->getController()->createUrl("admin/survey/sa/view/surveyid/" . $iSurveyID));
             $activationData = array('iSurveyID' => $iSurveyID, 'warning' => $warning, 'allowregister' => $allowregister, 'onclickAction' => $onclickAction, 'closedOnclickAction' => $closedOnclickAction, 'noOnclickAction' => $noOnclickAction);
             $aViewUrls['output'] = $this->getController()->renderPartial('/admin/survey/_activation_feedback', $activationData, true);
         }
         $this->_renderWrappedTemplate('survey', $aViewUrls, $aData);
     }
 }