⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compquest.php

📁 太烦了
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/** * class pluginTemplate * *  A template to get you started building templates.  Rename all pluginTemplate *  with the name of your plugin * * * */include_once(MODOSDATE_DIR . 'modPlugin.php');class compQuest extends modPlugin {   /**   * Holds the language phrases   *   * @access private   */   var $lang;      /**   * Holds the template data   *   * @access private   */   var $data;   /**   * The ID of logged in USER   *   * @access private   */   var $uid;   /**   * The name name of the plugin class.   *   * @access private   */   var $plugin_class_name = "compQuest";   /**   * Error.   *   * @access private   */   var $error=0;   /**   * The text that appears in the admin plugin list   *   * @access private   */   var $display_name = "Compatability Questionnaire";   /**   * Table that holds the sections   *   * @access private   */   var $lang_qsection_table = 'compQuest_section';   /**   * Table that holds the questions   *   * @access private   */   var $lang_qquestion_table = 'compQuest_question';   /**   * Table that holds the questions content   *   * @access private   */   var $lang_qcontent_table = 'compQuest_content';   /**   * The link text that appears on the user's menu   *   * @access private   */   var $user_menu_text  = "Compatability Questionnaire";   /**   * Table that holds the banners   *   * @access private   */   var $lang_qanswer_table = 'compQuest_answer';   /**   * Appear on users menu (true or false)   *   * @access private   */   var $user_menu_appear = true;   /**   * The link text that appears on the admin's menu   *   * @access private   */   var $admin_menu_text  = "Compatability Questionnaire";   /**   * Appear on admin's menu (true or false)   *   * @access private   */   var $admin_menu_appear = true;   /**   * Constructor   *   * @return   * @access public   */  function compQuest( )  {    $this->modPlugin();	$pluginDir = dirname(__FILE__).'/../';	$this->lang = $this->modLoadLang($pluginDir);  	$this->user_menu_text=$this->lang['user_title'];  	$this->admin_menu_text=$this->lang['admin_title'];  	$this->display_name=$this->lang['admin_title'];  } // end of member method pluginClass   /**   * Generates a section page for users   * Parameters: $sid (section ID)   *   * @return string   * @access public   */  function showSection($sid)  {	$data=$this->modGetAll($this->lang_qquestion_table,array('sid'=>$sid));	 foreach ($data as $item)	 {	 	if($item['type']==1)	 	{	 		$text2=$this->showQuestionType1($item,$lookuser);	 	}	 	if($item['type']==2)	 	{			$text2=$this->showQuestionType2($item,$lookuser);	 	}	 	$text.=$text2;	 }	 return $text;  }   /**   * Generates a question of type 1;   * Parameters: $item = array with all fields of the question table   * Important fields: $item['qid'], $item['maxopt'], $item['question'];   *   * @return string   * @access public   */  function showQuestionType1($item)  {  		$lenopt=7;	    $lenans=100-(2+$lenopt*$item['maxopt']);	 	for($i=0;$i<$item['maxopt'];$i++)	 		$nr[$i]=$i+1;        $ans=$this->modGetAll($this->lang_qcontent_table,array('qid'=>$item['qid']),'ord');     	$uans=$this->modGetAll($this->lang_qanswer_table,array('uid'=>$_SESSION['compQuest']['lookuser'],'qid'=>$item['qid']));        foreach($uans as $uanswer)        	$uresp[$uanswer['qcid']]=$uanswer['answer'];        $i=0;		foreach($ans as $answer)			$ans[$i++]['check']=$uresp[$answer['qcid']];		if($_SESSION['compQuest']['lookuser']!=$this->uid)		{			unset($uresp);     	$uans=$this->modGetAll($this->lang_qanswer_table,array('uid'=>$this->uid,'qid'=>$item['qid']));        foreach($uans as $uanswer)        	$uresp[$uanswer['qcid']]=$uanswer['answer'];        $i=0;		foreach($ans as $answer)			$ans[$i++]['check2']=$uresp[$answer['qcid']];		}     	$this->modSmartyAssign('lenopt',$lenopt);     	$this->modSmartyAssign('lenans',$lenans);     	$this->modSmartyAssign('nr',$nr);     	$this->modSmartyAssign('item',$item);     	$this->modSmartyAssign('ans',$ans);     	$this->modSmartyAssign('colspan',$item['maxopt']-2);	 	$text2=$this->modSmartyFetch("questiontype1.tpl");	 return $text2;  }   /**   * Generates a question of type 2;   * Parameters: $item = array with all fields of the question table   * Important fields: $item['qid'], $item['maxopt'], $item['minopt'], $item['showopt'], $item['question'];   *   * @return string   * @access public   */  function showQuestionType2($item)  {	 	$showopt=$item['showopt'];	 	$lenans=100/$showopt;	 	$lenans=(int)$lenans;	 	if ($_SESSION['compQuest']['lookuser']==$this->uid)	 	{	 	$ans=$this->modGetAll($this->lang_qcontent_table,array('qid'=>$item['qid']),'ord');	 	$uans=$this->modGetAll($this->lang_qanswer_table,array('uid'=>$_SESSION['compQuest']['lookuser'],'qid'=>$item['qid']));	 	foreach($uans as $uanswer)        	$uresp[$uanswer['qcid']]=1;        $i=0;        foreach($ans as $aanswer)			$ans[$i++]['check']=$uresp[$aanswer['qcid']];	 	$count=count($ans);	 	$lin=(int)($count/$showopt);	 	if($lin*$showopt!=$count) $lin++;	 	for($i=0;$i<$lin;$i++)	 		for($j=0;$j<$showopt;$j++)	 			{	 				$answer[$i][$j]['answer']=$ans[$j*$lin+$i]['answer'];	 				$answer[$i][$j]['qcid']=$ans[$j*$lin+$i]['qcid'];	 				$answer[$i][$j]['check']=$ans[$j*$lin+$i]['check'];	 			}  		}  		else  		{  			$ans=$this->modGetAll($this->lang_qcontent_table,array('qid'=>$item['qid']),'ord');	 		$uans=$this->modGetAll($this->lang_qanswer_table,array('uid'=>$_SESSION['compQuest']['lookuser'],'qid'=>$item['qid']));	 		foreach($uans as $uanswer)        		$uresp[$uanswer['qcid']]=1;	 		$uans=$this->modGetAll($this->lang_qanswer_table,array('uid'=>$this->uid,'qid'=>$item['qid']));	 		foreach($uans as $uanswer)        		$uresp2[$uanswer['qcid']]=1;  			$i=0;$s1="";$s2="";  		    foreach($ans as $aanswer)  		    if($uresp[$aanswer['qcid']] || $uresp2[$aanswer['qcid']]) {				$answer[$i]['check']=$uresp[$aanswer['qcid']];				if($uresp[$aanswer['qcid']])$s1=$aanswer['answer'];				$answer[$i]['check2']=$uresp2[$aanswer['qcid']];				if($uresp2[$aanswer['qcid']])$s2=$aanswer['answer'];				$answer[$i]['answer']=$aanswer['answer'];				$i++;  		    }  		   $this->modSmartyAssign('s1',$s1);  		   $this->modSmartyAssign('s2',$s2);  		}	 	$this->modSmartyAssign('answer',$answer);	 	$this->modSmartyAssign('lenans',$lenans);	 	$this->modSmartyAssign('item',$item);	 	$text2=$this->modSmartyFetch("questiontype2.tpl");	 return $text2;  }   /**   * Does the processing to display a user page.  Called from plugin.php   *   * @return array   * @access public   */   function  displayPluginPage() {   	 $this->modSmartyAssign('lang', $this->modGetLang());   	 $this->modSmartyAssign('plugin_name',$this->plugin_class_name);   	 $udata = $this->modGetLoggedInUser();	 $this->uid=$udata['id'];	 $section=$_POST['section'];	 $ok=1;	 if($section)	 {	 	$sid=$_POST['sid'];	 	$data=$this->modGetAll($this->lang_qquestion_table,array('sid'=>$sid));	 $ok=1;	 foreach ($data as $item)	 {	 	if($item['type']==1)	 	{	 		$qid=$item['qid'];			$this->modDeleteRows($this->lang_qanswer_table,array('qid'=>$qid,'uid'=>$this->uid));	 		$ans=$this->modGetAll($this->lang_qcontent_table,array('qid'=>$qid),'ord');	 		$max=count($ans);	 		$i=0;	 		foreach($ans as $answer)	 		{	 			$qcid=$answer['qcid'];	 			$resp=$_POST["q{$qid}_{$qcid}"];	 			if($resp) {	 				$i++;	 				$this->modAddRec($this->lang_qanswer_table,array('qid'=>$qid,'qcid'=>$qcid,'answer'=>$resp,'uid'=>$this->uid));	 				}	 		}	 		if($max!=$i) $ok=0;	 	}	 	if($item['type']==2)	 	{			$qid=$item['qid'];			$this->modDeleteRows($this->lang_qanswer_table,array('qid'=>$qid,'uid'=>$this->uid));			$ans=$this->modGetAll($this->lang_qcontent_table,array('qid'=>$qid),'ord');			$i=0;			foreach($ans as $answer)	 		{	 			$qcid=$answer['qcid'];	 			if(isset($_POST["q{$qid}_{$qcid}"]))	 			{	 				$i++;	 				$this->modAddRec($this->lang_qanswer_table,array('qid'=>$qid,'qcid'=>$qcid,'answer'=>1,'uid'=>$this->uid));	 			}	 		}	 		$minopt=$this->modGetOne($this->lang_qquestion_table,array('qid'=>$item['qid']),'minopt');	 		$maxopt=$this->modGetOne($this->lang_qquestion_table,array('qid'=>$item['qid']),'maxopt');	 		if($i<$minopt||$i>$maxopt) {$ok=0;	 									}	 	}	 }  	 if($ok)	 	$section++;	 }	 if(!$section) $section=1;	 $max=$this->modGetOne($this->lang_qsection_table,array(),'count(*)');	 if($section>$max)	 {	 	$ok=2;	 	$this->modSmartyAssign('ok',$ok);	 	$text=$this->modSmartyFetch("sectiontop.tpl");	 	$text.=$this->modSmartyFetch('thankyou.tpl');	 	$text.=$this->modSmartyFetch("sectionbottom.tpl");	 }	 else	 {	 if(isset($_GET['spage']))$section=$_GET['spage'];	 if($_GET['lookuser']) {$this->modSmartyAssign('lookuser',$_GET['lookuser']);$lookuser=$this->modGetAllUsers(array('username'=>$_GET['lookuser']));if($lookuser) {$_SESSION['compQuest']['lookuser']=$lookuser[0]['id'];$this->modSmartyAssign('lookid',$lookuser[0]['id']);} else {$eds=$this->modGetUser(array('userid'=>$_SESSION['compQuest']['lookuser'])); $this->modSmartyAssign('error',3); $this->modSmartyAssign('lookuser',$eds['username']);}}	 	else $_SESSION['compQuest']['lookuser']=$this->uid;	 $title=$this->modGetOne($this->lang_qsection_table,array('ord'=>$section),'title');	 $this->modSmartyAssign('title',$title);	 $this->modSmartyAssign('ok',$ok);	 $sid=$this->modGetOne($this->lang_qsection_table,array('ord'=>$section),'sid');	 $this->modSmartyAssign('sid',$sid);	 $this->modSmartyAssign('section',$section);	 $this->modSmartyAssign('prev',$section-1);	 $this->modSmartyAssign('next',$section+1);	 if($max==$section)$this->modSmartyAssign('next',0);	 $this->modSmartyAssign('pages',$this->modGetAll($this->lang_qsection_table,array(),'ord'));	 if($_SESSION['compQuest']['lookuser']!=$this->uid) {	 	$this->modSmartyAssign('ou',1);	 	$data=$this->modGetAll($this->lang_qquestion_table,array('sid'=>$sid));	 	$total=0;	 	$totalmatch=0;	 	$totalmatch2=0;	 	foreach ($data as $item)	 	{			$qid=$item['qid'];			$data2=$this->modGetAll($this->lang_qanswer_table,array('qid'=>$qid,'uid'=>$this->uid));			$total+=count($data2);			foreach ($data2 as $item2)			{				$qid=$item2['qid'];				$qcid=$item2['qcid'];				$datax=$this->modGetRow($this->lang_qanswer_table,array('qid'=>$qid,'qcid'=>$qcid,'uid'=>$_SESSION['compQuest']['lookuser']));				if($datax['answer']==$item2['answer']) $totalmatch++;				if(abs($datax['answer']-$item2['answer'])==1 && ($datax['answer'])) $totalmatch2++;			}	 	}	 	if ($total==0) {	 		$this->modSmartyAssign('proc1',0);	 	$this->modSmartyAssign('proc2',0);	 	}	 	else {	 	$this->modSmartyAssign('proc1',(int)($totalmatch/$total*100));	 	$this->modSmartyAssign('proc2',(int)($totalmatch2/$total*100));	 	}	 	$totalmatch=0;	 	$totalmatch2=0;	 	$data2=$this->modGetAll($this->lang_qanswer_table,array('uid'=>$this->uid));	 	$total=count($data2);		foreach ($data2 as $item2)		{			$qid=$item2['qid'];			$qcid=$item2['qcid'];			$datax=$this->modGetRow($this->lang_qanswer_table,array('qid'=>$qid,'qcid'=>$qcid,'uid'=>$_SESSION['compQuest']['lookuser']));			if($datax['answer']==$item2['answer']) $totalmatch++;			if(abs($datax['answer']-$item2['answer'])==1 && ($datax['answer'])) $totalmatch2++;		}		$this->modSmartyAssign('proc3',(int)($totalmatch/$total*100));	 	$this->modSmartyAssign('proc4',(int)($totalmatch2/$total*100));	 }	 	else $this->modSmartyAssign('ou',0);	 $text=$this->modSmartyFetch("sectiontop.tpl");	 $text.=$this->showSection($sid);	 $this->modSmartyAssign('smax',$max);	 if($_SESSION['compQuest']['lookuser']!=$this->uid) $this->modSmartyAssign('ok',2);	 $text.=$this->modSmartyFetch("sectionbottom.tpl");	 }	 return $text;   }   /**   * WARNING: USER IS NOT VALIDATED HERE.  BE CAREFUL   * Does the processing to display 100% plugin content.  Called from pluginraw.php   *   * @return array   * @access public   */   function  displayPluginContent() {   }    /**   * Returns the content that will appear in the left column of a page.  Designed to be overridden by plugins   *   * @return array   * @access public   */  function displayLeftCol() {  }    /**   * Returns the content that will appear in the main content area of the page.  This content will appear after the existing main content.  Designed to be overridden by plugins   *   * @return array   * @access public   */  function displayMain() {  }  /**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -