Skip to content

Commit

Permalink
Editing survey settings now possible! Fixed few errors and added two …
Browse files Browse the repository at this point in the history
…function in common_helper which were left previously.

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_ci@10381 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
sachdeva-shubham committed Jun 30, 2011
1 parent 17a00c4 commit 3ba134d
Show file tree
Hide file tree
Showing 18 changed files with 577 additions and 44 deletions.
1 change: 1 addition & 0 deletions application/config/routes.php
Expand Up @@ -46,6 +46,7 @@

//survey
$route['admin/survey/newsurvey'] = "admin/survey/index/newsurvey";
$route['admin/survey/editsurveysettings/(:num)'] = "admin/survey/index/editsurveysettings/$1";

/* End of file routes.php */
/* Location: ./application/config/routes.php */
236 changes: 230 additions & 6 deletions application/controllers/admin/database.php
Expand Up @@ -312,18 +312,242 @@ function index($action)
}
}
$this->session->set_userdata('flashmessage',$clang->gT("Survey text elements successfully saved."));
if ($databaseoutput != '')
{
echo $databaseoutput;
}
else
{
redirect(site_url('admin/survey/view/'.$surveyid));
}
}

if ($databaseoutput != '')
{
echo $databaseoutput;
}
else
if (($action == "updatesurveysettingsandeditlocalesettings" || $action == "updatesurveysettings") && bHasSurveyPermission($surveyid,'surveysettings','update'))
{
redirect(site_url('admin/survey/view/'.$surveyid));
$this->load->helper('surveytranslator');
$this->load->helper('database');
$formatdata=getDateFormatData($this->session->userdata('dateformat'));

$expires = $this->input->post('expires');
if (trim($expires)=="")
{
$expires=null;
}
else
{
$this->load->library('Date_Time_Converter',array($expires, $formatdata['phpdate'].' H:i'));
$datetimeobj = $this->date_time_converter; //new Date_Time_Converter($expires, $formatdata['phpdate'].' H:i');
$expires=$datetimeobj->convert("Y-m-d H:i:s");
}
$startdate = $this->input->post('startdate');
if (trim($startdate)=="")
{
$startdate=null;
}
else
{
$this->load->library('Date_Time_Converter',array($startdate,$formatdata['phpdate'].' H:i'));
$datetimeobj = $this->date_time_converter; //new Date_Time_Converter($startdate,$formatdata['phpdate'].' H:i');
$startdate=$datetimeobj->convert("Y-m-d H:i:s");
}

//make sure only numbers are passed within the $_POST variable
$tokenlength = (int) $this->input->post('tokenlength');
//$_POST['tokenlength'] = (int) $_POST['tokenlength'];

//token length has to be at least 5, otherwise set it to default (15)
if($tokenlength < 5)
{
$tokenlength = 15;
}


CleanLanguagesFromSurvey($surveyid,$this->input->post('languageids'));

FixLanguageConsistency($surveyid,$this->input->post('languageids'));
$template = $this->input->post('template');

if($this->session->userdata('USER_RIGHT_SUPERADMIN') != 1 && $this->session->userdata('USER_RIGHT_MANAGE_TEMPLATE') != 1 && !hasTemplateManageRights($this->session->userdata('loginID'), $template)) $template = "default";

//$sql = "SELECT * FROM ".$this->db->dbprefix."surveys WHERE sid={$postsid}"; // We are using $dbrepfix here instead of db_table_name on purpose because GetUpdateSQL doesn't work correclty on Postfres with a quoted table name
//$rs = db_execute_assoc($sql); // Checked
$updatearray= array('admin'=> $this->input->post('admin'),
'expires'=>$expires,
'adminemail'=> $this->input->post('adminemail'),
'startdate'=>$startdate,
'bounce_email'=> $this->input->post('bounce_email'),
'anonymized'=> $this->input->post('anonymized'),
'faxto'=> $this->input->post('faxto'),
'format'=> $this->input->post('format'),
'savetimings'=> $this->input->post('savetimings'),
'template'=>$template,
'assessments'=> $this->input->post('assessments'),
'language'=> $this->input->post('language'),
'additional_languages'=> $this->input->post('languageids'),
'datestamp'=> $this->input->post('datestamp'),
'ipaddr'=> $this->input->post('ipaddr'),
'refurl'=> $this->input->post('refurl'),
'publicgraphs'=> $this->input->post('publicgraphs'),
'usecookie'=> $this->input->post('usecookie'),
'allowregister'=> $this->input->post('allowregister'),
'allowsave'=> $this->input->post('allowsave'),
'navigationdelay'=> $this->input->post('navigationdelay'),
'printanswers'=> $this->input->post('printanswers'),
'publicstatistics'=> $this->input->post('publicstatistics'),
'autoredirect'=> $this->input->post('autoredirect'),
'showXquestions'=> $this->input->post('showXquestions'),
'showgroupinfo'=> $this->input->post('showgroupinfo'),
'showqnumcode'=> $this->input->post('showqnumcode'),
'shownoanswer'=> $this->input->post('shownoanswer'),
'showwelcome'=> $this->input->post('showwelcome'),
'allowprev'=> $this->input->post('allowprev'),
'allowjumps'=> $this->input->post('allowjumps'),
'nokeyboard'=> $this->input->post('nokeyboard'),
'showprogress'=> $this->input->post('showprogress'),
'listpublic'=> $this->input->post('public'),
'htmlemail'=> $this->input->post('htmlemail'),
'tokenanswerspersistence'=> $this->input->post('tokenanswerspersistence'),
'alloweditaftercompletion'=> $this->input->post('alloweditaftercompletion'),
'usecaptcha'=> $this->input->post('usecaptcha'),
'emailresponseto'=>trim($this->input->post('emailresponseto')),
'emailnotificationto'=>trim($this->input->post('emailnotificationto')),
'tokenlength'=>$tokenlength
);


/**$usquery=$connect->GetUpdateSQL($rs, $updatearray, false, get_magic_quotes_gpc());
if ($usquery) {
$usresult = $connect->Execute($usquery) or safe_die("Error updating<br />".$usquery."<br /><br /><strong>".$connect->ErrorMsg()); // Checked
}
*/
$condition = array('sid' => $surveyid);
$this->load->model('surveys_model');
$this->surveys_model->updateSurvey($updatearray,$condition);
$sqlstring ='';

foreach (GetAdditionalLanguagesFromSurveyID($surveyid) as $langname)
{
if ($langname)
{
$sqlstring .= "AND surveyls_language <> '".$langname."' ";
}
}

// Add base language too
$sqlstring .= "AND surveyls_language <> '".GetBaseLanguageFromSurveyID($surveyid)."' ";

$usquery = "DELETE FROM ".$this->db->dbprefix."surveys_languagesettings WHERE surveyls_survey_id={$surveyid} ".$sqlstring;

$usresult = db_execute_assoc($usquery) or safe_die("Error deleting obsolete surveysettings<br />".$usquery."<br /><br /><strong>"); // Checked

foreach (GetAdditionalLanguagesFromSurveyID($surveyid) as $langname)
{
if ($langname)
{
$usquery = "select * from ".$this->db->dbprefix."surveys_languagesettings where surveyls_survey_id={$surveyid} and surveyls_language='".$langname."'";
$usresult = db_execute_assoc($usquery) or safe_die("Error deleting obsolete surveysettings<br />".$usquery."<br /><br /><strong>"); // Checked
if ($usresult->num_rows()==0)
{
$this->load->library('Limesurvey_lang',array($langname));
$bplang = $this->limesurvey_lang;//new limesurvey_lang($langname);
$aDefaultTexts=aTemplateDefaultTexts($bplang,'unescaped');
if (getEmailFormat($surveyid) == "html")
{
$ishtml=true;
$aDefaultTexts['admin_detailed_notification']=$aDefaultTexts['admin_detailed_notification_css'].$aDefaultTexts['admin_detailed_notification'];
}
else
{
$ishtml=false;
}
$languagedetails=getLanguageDetails($langname);

$insertdata = array(
'surveyls_survey_id' => $surveyid,
'surveyls_language' => $langname,
'surveyls_title' => '',
'surveyls_email_invite_subj' => $aDefaultTexts['invitation_subject'],
'surveyls_email_invite' => $aDefaultTexts['invitation'],
'surveyls_email_remind_subj' => $aDefaultTexts['reminder_subject'],
'surveyls_email_remind' => $aDefaultTexts['reminder'],
'surveyls_email_confirm_subj' => $aDefaultTexts['confirmation_subject'],
'surveyls_email_confirm' => $aDefaultTexts['confirmation'],
'surveyls_email_register_subj' => $aDefaultTexts['registration_subject'],
'surveyls_email_register' => $aDefaultTexts['registration'],
'email_admin_notification_subj' => $aDefaultTexts['admin_notification_subject'],
'email_admin_notification' => $aDefaultTexts['admin_notification'],
'email_admin_responses_subj' => $aDefaultTexts['admin_detailed_notification_subject'],
'email_admin_responses' => $aDefaultTexts['admin_detailed_notification'],
'surveyls_dateformat' => $languagedetails['dateformat']
);
/**$usquery = "INSERT INTO ".db_table_name('surveys_languagesettings')
." (surveyls_survey_id, surveyls_language, surveyls_title, "
." surveyls_email_invite_subj, surveyls_email_invite, "
." surveyls_email_remind_subj, surveyls_email_remind, "
." surveyls_email_confirm_subj, surveyls_email_confirm, "
." surveyls_email_register_subj, surveyls_email_register, "
." email_admin_notification_subj, email_admin_notification, "
." email_admin_responses_subj, email_admin_responses, "
." surveyls_dateformat) "
." VALUES ({$postsid}, '".$langname."', '',"
.db_quoteall($aDefaultTexts['invitation_subject']).","
.db_quoteall($aDefaultTexts['invitation']).","
.db_quoteall($aDefaultTexts['reminder_subject']).","
.db_quoteall($aDefaultTexts['reminder']).","
.db_quoteall($aDefaultTexts['confirmation_subject']).","
.db_quoteall($aDefaultTexts['confirmation']).","
.db_quoteall($aDefaultTexts['registration_subject']).","
.db_quoteall($aDefaultTexts['registration']).","
.db_quoteall($aDefaultTexts['admin_notification_subject']).","
.db_quoteall($aDefaultTexts['admin_notification']).","
.db_quoteall($aDefaultTexts['admin_detailed_notification_subject']).","
.db_quoteall($aDefaultTexts['admin_detailed_notification']).","
.$languagedetails['dateformat'].")"; */
$this->load->model('surveys_languagesettings_model');

$usresult = $this->surveys_languagesettings_model->insertNewSurvey($insertdata);
unset($bplang);
//$usresult = $connect->Execute($usquery) or safe_die("Error deleting obsolete surveysettings<br />".$usquery."<br /><br />".$connect->ErrorMsg()); // Checked
}
}
}



if ($usresult)
{
$surveyselect = getsurveylist();
$this->session->set_userdata('flashmessage', $clang->gT("Survey settings were successfully saved."));

}
else
{
$databaseoutput .= "<script type=\"text/javascript\">\n<!--\n alert(\"".$clang->gT("Survey could not be updated","js")."\n\")\n //-->\n</script>\n";
}

if ($databaseoutput != '')
{
echo $databaseoutput;
}
else
{
//redirect(site_url('admin/survey/view/'.$surveyid));

if ($this->input->post('action') == "updatesurveysettingsandeditlocalesettings")
{
redirect(site_url('admin/survey/editlocalsettings/'.$surveyid));
}
else
{
redirect(site_url('admin/survey/view/'.$surveyid));
}

}
}




}

/**
Expand Down
31 changes: 19 additions & 12 deletions application/controllers/admin/survey.php
Expand Up @@ -155,11 +155,13 @@ function delete()
function editlocalsettings($surveyid)
{
$clang = $this->limesurvey_lang;


$css_admin_includes[] = $this->config->item('styleurl')."admin/default/superfish.css";
$this->config->set_item("css_admin_includes", $css_admin_includes);
self::_js_admin_includes(base_url().'application/scripts/surveysettings.js');
self::_getAdminHeader();
self::_showadminmenu();

self::_surveybar($surveyid);
if(bHasSurveyPermission($surveyid,'surveylocale','read'))
{

Expand Down Expand Up @@ -454,13 +456,17 @@ function copy()

}

function index($action)
function index($action,$surveyid=null)
{
global $surveyid;
//global $surveyid;

self::_js_admin_includes(base_url().'application/scripts/surveysettings.js');
$css_admin_includes[] = $this->config->item('styleurl')."admin/default/superfish.css";
$this->config->set_item("css_admin_includes", $css_admin_includes);
self::_getAdminHeader();
self::_showadminmenu();
if (!is_null($surveyid))
self::_surveybar($surveyid);

if(!bHasSurveyPermission($surveyid,'surveysettings','read') && !bHasGlobalPermission('USER_RIGHT_CREATE_SURVEY'))
{
Expand All @@ -485,14 +491,14 @@ function index($action)
// header
$editsurvey .= "<div class='header ui-widget-header'>" . $clang->gT("Create, import, or copy survey") . "</div>\n";
} elseif ($action == "editsurveysettings") {
$esrow = self::_fetchSurveyInfo('editsurvey');
$esrow = self::_fetchSurveyInfo('editsurvey',$surveyid);
// header
$editsurvey = "<div class='header ui-widget-header'>".$clang->gT("Edit survey settings")."</div>\n";
$editsurvey .= "<div class='header ui-widget-header'>".$clang->gT("Edit survey settings")."</div>\n";
}
if ($action == "newsurvey") {
$editsurvey .= self::_generalTabNewSurvey();
} elseif ($action == "editsurveysettings") {
$editsurvey = self::_generalTabEditSurvey($surveyid,$esrow);
$editsurvey .= self::_generalTabEditSurvey($surveyid,$esrow);
}

$editsurvey .= self::_tabPresentationNavigation($esrow);
Expand All @@ -502,7 +508,7 @@ function index($action)

if ($action == "newsurvey") {
$editsurvey .= "<input type='hidden' id='surveysettingsaction' name='action' value='insertsurvey' />\n";
$this->session->set_userdata(array('action' => 'insertsurvey'));
//$this->session->set_userdata(array('action' => 'insertsurvey'));
} elseif ($action == "editsurveysettings") {
$editsurvey .= "<input type='hidden' id='surveysettingsaction' name='action' value='updatesurveysettings' />\n"
. "<input type='hidden' name='sid' value=\"{$esrow['sid']}\" />\n"
Expand Down Expand Up @@ -536,16 +542,17 @@ function index($action)
$editsurvey .= "<p><button onclick=\"$cond {document.getElementById('surveysettingsaction').value = 'updatesurveysettingsandeditlocalesettings'; document.getElementById('addnewsurvey').submit();}\" class='standardbtn' >" . $clang->gT("Save & edit survey text elements") . " >></button></p>\n";
}
}
$editsurvey .= self::_loadEndScripts();

//echo $editsurvey;
$data['display'] = $editsurvey;
$this->load->view('survey_view',$data);
$editsurvey .= self::_loadEndScripts();
self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual"));

}


function _fetchSurveyInfo($action)
function _fetchSurveyInfo($action,$surveyid=null)
{
if ($action == 'newsurvey')
{
Expand Down Expand Up @@ -781,11 +788,11 @@ function _generalTabEditSurvey($surveyid,$esrow)
// End General TAB
$editsurvey .= "</div>\n";
*/

$data['action'] = "editsurveysettings";
$data['clang'] = $clang;
$data['esrow'] = $esrow;
$data['surveyid'] = $surveyid;
return $this->load->view('admin/survey/superview/superGeneralEditSurey_view',$data, true);
return $this->load->view('admin/survey/superview/superGeneralEditSurvey_view',$data, true);

}

Expand Down

0 comments on commit 3ba134d

Please sign in to comment.