Skip to content

Commit

Permalink
New feature: Token section workflow improvements by GCI participant N…
Browse files Browse the repository at this point in the history
…ano8Blazex

Dev GCI participants: please update your CI sources

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_ci@11475 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Nov 24, 2011
1 parent b8ab9fb commit 6f69132
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 111 deletions.
160 changes: 92 additions & 68 deletions application/controllers/admin/tokens.php
Expand Up @@ -35,7 +35,7 @@ function __construct()
/**
* Show token index page, handle token database
*/
function index($surveyid)
function index($surveyid,$limit=15,$start=0,$order=false,$searchstring=false)
{
$surveyid = sanitize_int($surveyid);

Expand All @@ -47,6 +47,7 @@ function index($surveyid)

self::_js_admin_includes(base_url()."scripts/admin/tokens.js");

$this->load->model("tokens_dynamic_model");
$this->load->helper("surveytranslator");

$dateformatdetails=getDateFormatData($this->session->userdata('dateformat'));
Expand All @@ -58,6 +59,8 @@ function index($surveyid)
}

$data['surveyprivate'] = $thissurvey['anonymized'];


// CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY
$tokenexists=tableExists('tokens_'.$surveyid);
if (!$tokenexists) //If no tokens table exists
Expand All @@ -70,13 +73,17 @@ function index($surveyid)
$data['thissurvey']=$thissurvey;
$data['imageurl'] = $this->config->item('imageurl');
$data['surveyid']=$surveyid;

$this->load->model("tokens_dynamic_model");
$data['queries']=$this->tokens_dynamic_model->tokensSummary($surveyid);
$data['currentpath'] = 'index';

// set $data so the browse view can use it
self::_configureBrowsingData($surveyid,$limit,$start,$order,$searchstring, $data);

self::_getAdminHeader();
$this->load->view("admin/token/tokenbar",$data);
$this->load->view("admin/token/tokensummary",$data);
$this->load->view("admin/token/browse",$data);
$this->load->view("admin/token/tokendatabaseoptions",$data);
self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual"));
}
}
Expand Down Expand Up @@ -252,80 +259,24 @@ function bounceprocessing($surveyid)
function browse($surveyid,$limit=50,$start=0,$order=false,$searchstring=false)
{
$surveyid = sanitize_int($surveyid);
$limit = (int) $limit;
$start = (int) $start;

$clang=$this->limesurvey_lang;
$this->load->model("tokens_dynamic_model");
$tkcount=$this->tokens_dynamic_model->totalRecords($surveyid);

self::_js_admin_includes(base_url()."scripts/admin/tokens.js");

//if (!isset($limit)) {$limit=(int)returnglobal('limit');}
//if ($limit==0) $limit=50;
//if (!isset($start)) {$start=(int)returnglobal('start');}
//if (!isset($limit)) {$limit = 100;}
//if (!isset($start)) {$start = 0;} if ($limit > $tkcount) {$limit=$tkcount;}
$next=$start+$limit;
$last=$start-$limit;
$end=$tkcount-$limit;
if ($end < 0) {$end=0;}
if ($last <0) {$last=0;}
if ($next >= $tkcount) {$next=$tkcount-$limit;}
if ($end < 0) {$end=0;}

$baselanguage = GetBaseLanguageFromSurveyID($surveyid);
$data['next']=$next;
$data['last']=$last;
$data['end']=$end;
if(!$order) $order=$this->input->post("order");
$order=preg_replace('/[^_ a-z0-9-]/i', '',$order);
if ($order=="") {$order = "tid";}
if($this->input->post("limit")) $limit = $this->input->post("limit");
if($this->input->post("start")) $start = $this->input->post("start");
//if (!isset($order)) {$order=preg_replace('/[^_ a-z0-9-]/i', '', returnglobal('order'));}
//if (!isset($limit)) {$limit=(int)returnglobal('limit');}

//ALLOW SELECTION OF NUMBER OF RECORDS SHOWN $thissurvey=getSurveyInfo($surveyid);

if(!$searchstring) $searchstring=$this->input->post("searchstring");
/*$bquery = "SELECT * FROM ".db_table_name("tokens_$surveyid");
if ($searchstring)
{
$sSearch=db_quote($searchstring);
$bquery .= " WHERE firstname LIKE '%{$sSearch}%' "
. "OR lastname LIKE '%{$sSearch}%' "
. "OR email LIKE '%{$sSearch}%' "
. "OR emailstatus LIKE '%{$sSearch}%' "
. "OR token LIKE '%{$sSearch}%'";
}
if (!isset($order) || !$order) {$bquery .= " ORDER BY tid";}
else {$bquery .= " ORDER BY $order"; }
$bresult = db_select_limit_assoc($bquery, $limit, $start) or safe_die ($clang->gT("Error").": $bquery<br />".$connect->ErrorMsg());*/
if($searchstring)
{
$idata = array("firstname"=>$searchstring,
"lastname"=>$searchstring,
"email"=>$searchstring,
"emailstatus"=>$searchstring,
"token"=>$searchstring);
}
else
{
$idata = false;
}

$data['bresult'] = $this->tokens_dynamic_model->getAllRecords($surveyid,false,$limit,$start,$order,$idata);
$data['clang']=$clang;
$data['thissurvey']=getSurveyInfo($surveyid);
$data['searchstring']=$searchstring;
$data['imageurl'] = $this->config->item('imageurl');
$data['surveyid']=$surveyid;
$data['bgc']="";
$data['limit']=$limit;
$data['start']=$start;
$data['order']=$order;
$data['surveyprivate'] = $data['thissurvey']['anonymized'];
$data['currentpath'] = 'browse';


// set $data so the browse view can use it
self::_configureBrowsingData($surveyid,$limit,$start,$order,$searchstring, $data);

self::_getAdminHeader();
$this->load->view("admin/token/tokenbar",$data);
Expand Down Expand Up @@ -406,7 +357,7 @@ function addnew($surveyid)
$data['success']=false;
}

$data['clang']=$clang;
/*$data['clang']=$clang;
$thissurvey=getSurveyInfo($surveyid);
$data['thissurvey']=$thissurvey;
$data['imageurl'] = $this->config->item('imageurl');
Expand All @@ -415,8 +366,21 @@ function addnew($surveyid)
self::_getAdminHeader();
$this->load->view("admin/token/tokenbar",$data);
$this->load->view("admin/token/addtokenpost",$data);
self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual"));
//$this->load->view("admin/token/addtokenpost",$data);
self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual"));*/

// instead of going to success page, go back to new token page and have popup instead
if ($data['success']==true) {
$sTokenName = $data['firstname'] . " " . $data['lastname'];
if (($sTokenName == " ")||($sTokenName == "")) {
$sTokenName = $clang->gT("-------");
}
$sFlashMessage = "<strong>" . $clang->gT("Success") . "</strong><br />" . $clang->gT("New token was added.") . "<br />[" . $clang->gT("Name") . ": " . $sTokenName . "]";
} else {
$sFlashMessage = $clang->gT("Failed") . $clang->gT("There is already an entry with that exact token in the table. The same token cannot be used in multiple entries.");
}
$this->session->set_userdata('flashmessage', $sFlashMessage);
self::_handletokenform($surveyid,"addnew");
}
else
{
Expand Down Expand Up @@ -1736,4 +1700,64 @@ function _newtokentable($surveyid)
return;
}
}

/**
* Configure data for browsing
* to avoid repetitive code, Used in index() and browse()
*/
function _configureBrowsingData($surveyid,$limit,$start,$order,$searchstring, &$data)
{
$limit = (int) $limit; // for browsing
$start = (int) $start; // for browsing

/* Browsing data*/
$tkcount=$this->tokens_dynamic_model->totalRecords($surveyid);

//if (!isset($limit)) {$limit=(int)returnglobal('limit');}
//if ($limit==0) $limit=50;
//if (!isset($start)) {$start=(int)returnglobal('start');}
//if (!isset($limit)) {$limit = 100;}
//if (!isset($start)) {$start = 0;} if ($limit > $tkcount) {$limit=$tkcount;}
$next=$start+$limit;
$last=$start-$limit;
$end=$tkcount-$limit;
if ($end < 0) {$end=0;}
if ($last <0) {$last=0;}
if ($next >= $tkcount) {$next=$tkcount-$limit;}
if ($end < 0) {$end=0;}

$data['next']=$next;
$data['last']=$last;
$data['end']=$end;

if(!$order) $order=$this->input->post("order");
$order=preg_replace('/[^_ a-z0-9-]/i', '',$order);
if ($order=="") {$order = "tid";}

if($this->input->post("limit")) $limit = $this->input->post("limit");
if($this->input->post("start")) $start = $this->input->post("start");

//ALLOW SELECTION OF NUMBER OF RECORDS SHOWN
if(!$searchstring) $searchstring=$this->input->post("searchstring");
if($searchstring)
{
$idata = array("firstname"=>$searchstring,
"lastname"=>$searchstring,
"email"=>$searchstring,
"emailstatus"=>$searchstring,
"token"=>$searchstring);
}
else
{
$idata = false;
}

/*browsing*/
$data['bresult'] = $this->tokens_dynamic_model->getAllRecords($surveyid,false,$limit,$start,$order,$idata);
$data['searchstring']=$searchstring;
$data['bgc']="";
$data['limit']=$limit;
$data['start']=$start;
$data['order']=$order;
}
}

0 comments on commit 6f69132

Please sign in to comment.