From e7ffe1bdfa77f5bbbaa4fcd302469dcf6021b2b7 Mon Sep 17 00:00:00 2001 From: Gautam Gupta Date: Mon, 5 Dec 2011 22:12:21 +0000 Subject: [PATCH] Porting the functionality 'Add dummy tokens' to the Yii PHP framework - GCI Task #7127236 by gautamgupta git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_yii@11591 b72ed6b6-b9f8-46b5-92b4-906544132732 --- application/controllers/admin/browse.php | 12 +-- application/controllers/admin/tokens.php | 93 +++++++++---------- application/models/Tokens_dynamic.php | 11 ++- .../views/admin/token/dummytokenform.php | 4 +- 4 files changed, 56 insertions(+), 64 deletions(-) diff --git a/application/controllers/admin/browse.php b/application/controllers/admin/browse.php index 00cf14fbb46..88fd0267568 100644 --- a/application/controllers/admin/browse.php +++ b/application/controllers/admin/browse.php @@ -23,10 +23,10 @@ * @subpackage Backend */ class browse extends Survey_Common_Action { - + private $yii; private $controller; - + public function run() { $this->yii = Yii::app(); @@ -53,11 +53,11 @@ function action($surveyid = null, $subaction = null, $var1 = null, $var2 = null, // Some test in response table if (!isset($surveyid) && !isset($subaction)) //NO SID OR ACTION PROVIDED { - show_error("\t
" + die("\t
" . $clang->gT("Browse Responses")."
" . $clang->gT("Error")."\t
\n" . $clang->gT("You have not selected a survey to browse.")."
\n" - ."
\n" + ."getController()->createUrl("/admin")."', '_top')\" />
\n" ."
"); return; } @@ -251,7 +251,7 @@ function action($surveyid = null, $subaction = null, $var1 = null, $var2 = null, if (isset($rlanguage)) {$data['rlanguage'] = $rlanguage;} $data['next'] = $next; $data['last'] = $last; - + $this->controller->render("/admin/browse/browseidheader_view", $data); $idresult = db_execute_assoc($idquery) or safe_die ("Couldn't get entry
$idquery
".$connect->ErrorMsg()); @@ -696,7 +696,7 @@ function action($surveyid = null, $subaction = null, $var1 = null, $var2 = null, $data['last'] = $last; $data['next'] = $next; $data['end'] = $end; - + $this->controller->render("/admin/browse/browseallheader_view", $data); foreach ($dtresult->readAll() as $dtrow) diff --git a/application/controllers/admin/tokens.php b/application/controllers/admin/tokens.php index f16239dde8d..bfb8674d090 100644 --- a/application/controllers/admin/tokens.php +++ b/application/controllers/admin/tokens.php @@ -46,6 +46,8 @@ public function run($sa) $this->route('import', array('surveyid')); elseif ($sa == 'importldap') $this->route('importldap', array('surveyid')); + elseif ($sa == 'adddummys') + $this->route('adddummys', array('surveyid', 'subaction')); } /** @@ -627,34 +629,34 @@ function delete($surveyid, $tokenid=null,$limit=50,$start=0,$order=false,$search /** * Add dummy tokens form */ - function adddummys($surveyid) + function adddummys($surveyid, $subaction = '') { $surveyid = sanitize_int($surveyid); - $clang=$this->limesurvey_lang; + $clang = $this->getController()->lang; if(!bHasSurveyPermission($surveyid, 'tokens','create')) { - show_error("no permissions"); // TODO Replace + die("No permissions."); // TODO Replace } - if ($this->input->post("subaction")) + $this->getController()->loadHelper("surveytranslator"); + + if (!empty($subaction) && $subaction == 'add') { - $this->load->model("tokens_dynamic_model"); - $_POST=$this->input->post(); + $this->getController()->loadLibrary('Date_Time_Converter'); + $dateformatdetails = getDateFormatData(Yii::app()->session['dateformat']); + //Fix up dates and match to database format if (trim($_POST['validfrom'])=='') { - $_POST['validfrom']=null; - } - - else - { - $datetimeobj = new Date_Time_Converter(trim($_POST['validfrom']), $dateformatdetails['phpdate'].' H:i'); - $_POST['validfrom'] =$datetimeobj->convert('Y-m-d H:i:s'); + $_POST['validfrom'] = null; + } else { + $datetimeobj = new Date_Time_Converter(array(trim($_POST['validfrom']), $dateformatdetails['phpdate'].' H:i')); + $_POST['validfrom'] = $datetimeobj->convert('Y-m-d H:i:s'); } if (trim($_POST['validuntil'])=='') {$_POST['validuntil']=null;} else { - $datetimeobj = new Date_Time_Converter(trim($_POST['validuntil']), $dateformatdetails['phpdate'].' H:i'); - $_POST['validuntil'] =$datetimeobj->convert('Y-m-d H:i:s'); + $datetimeobj = new Date_Time_Converter(array(trim($_POST['validuntil']), $dateformatdetails['phpdate'].' H:i')); + $_POST['validuntil'] = $datetimeobj->convert('Y-m-d H:i:s'); } $santitizedtoken=''; @@ -668,7 +670,7 @@ function adddummys($surveyid) 'emailstatus' => 'OK', 'token' => $santitizedtoken, 'language' => sanitize_languagecode($_POST['language']), - 'sent' => 'N', + 'sent' => 'N', 'remindersent' => 'N', 'completed' => 'N', 'usesleft' => $_POST['usesleft'], @@ -676,10 +678,10 @@ function adddummys($surveyid) 'validuntil' => $_POST['validuntil']); // add attributes - $attrfieldnames=GetAttributeFieldnames($surveyid); + $attrfieldnames = GetAttributeFieldnames($surveyid); foreach ($attrfieldnames as $attr_name) { - $data[$attr_name]=$_POST[$attr_name]; + $data[$attr_name] = $_POST[$attr_name]; } //$tblInsert=db_table_name('tokens_'.$surveyid); $amount = sanitize_int($_POST['amount']); @@ -687,9 +689,9 @@ function adddummys($surveyid) for ($i=0; $i<$amount;$i++){ $dataToInsert = $data; - $dataToInsert['firstname'] = str_replace('{TOKEN_COUNTER}',"$i",$dataToInsert['firstname']); - $dataToInsert['lastname'] = str_replace('{TOKEN_COUNTER}',"$i",$dataToInsert['lastname']); - $dataToInsert['email'] = str_replace('{TOKEN_COUNTER}',"$i",$dataToInsert['email']); + $dataToInsert['firstname'] = str_replace('{TOKEN_COUNTER}', $i, $dataToInsert['firstname']); + $dataToInsert['lastname'] = str_replace('{TOKEN_COUNTER}', $i, $dataToInsert['lastname']); + $dataToInsert['email'] = str_replace('{TOKEN_COUNTER}', $i, $dataToInsert['email']); $isvalidtoken = false; while ($isvalidtoken == false) @@ -700,46 +702,37 @@ function adddummys($surveyid) $existingtokens[$newtoken]=null; } } + $dataToInsert['token'] = $newtoken; - //$tblInsert=db_table_name('tokens_'.$surveyid); - //$inresult = $connect->AutoExecute($tblInsert, $dataToInsert, 'INSERT') or safe_die ("Add new record failed:
\n$inquery
\n".$connect->ErrorMsg()); - $inresult = $this->tokens_dynamic_model->insertToken($surveyid,$dataToInsert); + Tokens_dynamic::insertToken($surveyid, $dataToInsert); } - self::_getAdminHeader(); - self::_showMessageBox($clang->gT("Success"), + $this->getController()->_getAdminHeader(); + $this->getController()->_showMessageBox($clang->gT("Success"), $clang->gT("New dummy tokens were added.")."

\n\n"); - self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual")); + .$clang->gT("Display tokens")."' onclick=\"window.open('".$this->getController()->createUrl("admin/tokens/sa/browse/surveyid/$surveyid")."', '_top')\" />\n"); + $this->getController()->_getAdminFooter("http://docs.limesurvey.org", $clang->gT("LimeSurvey online manual")); } else { - $this->load->model("tokens_dynamic_model"); - $tkcount=$this->tokens_dynamic_model->totalRecords($surveyid); - $this->load->helper("surveytranslator"); - //get token length from survey settings - $this->load->model("surveys_model"); - $query = $this->surveys_model->getSomeRecords(array("tokenlength"),array("sid"=>$surveyid)); - $row = $query->row_array(); - $tokenlength = $row['tokenlength']; + $tkcount = Tokens_dynamic::totalRecords($surveyid); + $tokenlength = Yii::app()->db->createCommand()->select('tokenlength')->from('{{surveys}}')->where('sid='.$surveyid)->query()->readColumn(0); - //if tokenlength is not set or there are other problems use the default value (15) - if(!isset($tokenlength) || $tokenlength == '') - { + if(empty($tokenlength)) { $tokenlength = 15; } - $data['clang']=$clang; - $thissurvey=getSurveyInfo($surveyid); - $data['thissurvey']=$thissurvey; - $data['imageurl'] = $this->config->item('imageurl'); - $data['surveyid']=$surveyid; - $data['tokenlength']=$tokenlength; - $data['dateformatdetails']=getDateFormatData($this->session->userdata('dateformat')); + $data['clang'] = $clang; + $thissurvey = getSurveyInfo($surveyid); + $data['thissurvey'] = $thissurvey; + $data['imageurl'] = Yii::app()->getConfig('imageurl'); + $data['surveyid'] = $surveyid; + $data['tokenlength'] = $tokenlength; + $data['dateformatdetails'] = getDateFormatData(Yii::app()->session['dateformat']); - self::_getAdminHeader(); - $this->load->view("admin/token/tokenbar",$data); - $this->load->view("admin/token/dummytokenform",$data); - self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual")); + $this->getController()->_getAdminHeader(); + $this->getController()->render("/admin/token/tokenbar",$data); + $this->getController()->render("/admin/token/dummytokenform",$data); + $this->getController()->_getAdminFooter("http://docs.limesurvey.org", $clang->gT("LimeSurvey online manual")); } } diff --git a/application/models/Tokens_dynamic.php b/application/models/Tokens_dynamic.php index e4ee7976d21..83668d03ced 100644 --- a/application/models/Tokens_dynamic.php +++ b/application/models/Tokens_dynamic.php @@ -104,7 +104,7 @@ public function summary() return $data; } - + public function totalRecords($iSurveyID) { $tksq = "SELECT count(tid) FROM {{tokens_{$iSurveyID}}}"; @@ -112,7 +112,7 @@ public function totalRecords($iSurveyID) $tkr = $tksr->read(); return $tkr["count(tid)"]; } - + public function ctquery($iSurveyID,$SQLemailstatuscondition,$tokenid=false,$tokenids=false) { $ctquery = "SELECT * FROM {{tokens_{$iSurveyID}}} WHERE ((completed ='N') or (completed='')) AND ((sent ='N') or (sent='')) AND token !='' AND email != '' $SQLemailstatuscondition"; @@ -132,10 +132,11 @@ public function emquery($iSurveyID,$SQLemailstatuscondition,$maxemails,$tokenid= Yii::app()->loadHelper("database"); return db_select_limit_assoc($emquery,$maxemails); } - - function insertToken($iSurveyID,$data) + + function insertToken($iSurveyID, $data) { - return Yii::app()->db->createCommand()->insert("{{tokens_".$iSurveyID.'}}', $data)->query(); + self::sid($iSurveyID); + return Yii::app()->db->createCommand()->insert(self::tableName(), $data); } } ?> diff --git a/application/views/admin/token/dummytokenform.php b/application/views/admin/token/dummytokenform.php index 1019b74db5d..276d056ea48 100644 --- a/application/views/admin/token/dummytokenform.php +++ b/application/views/admin/token/dummytokenform.php @@ -1,7 +1,7 @@
gT("Create dummy tokens"); ?>
-
+
  • gT("Auto");?> @@ -48,7 +48,5 @@ ?>

-

- \ No newline at end of file