";
$tab->description=null;
}
$data=$this->_getData($tab,$user);
$content="";
foreach($data as $record){
$content.=$this->_getViewTabContents($tab->tabid,$record);
}
//Modify the view to be a one single table
if($this->params->get('showAsLists','0')==1){
$content=str_replace('','',$content);
$content=ereg_replace('
";
}
return $ret;
}
function _getData($tab,$user){
global $database;
$database->setQuery("SELECT * FROM #__comprofiler_listtab_".$tab->tabid." WHERE userid='".$user->id."' and tabid='".$tab->tabid."'");
return $database->loadObjectList();
}
function _getHeader($tab,$user){
global $database;
$ret ="";
$ret .="",$retArr[$i]);
$end.="\nvar temp=('".str_replace("\n","",str_replace('inputField : "','inputField : "new\'+count'.$tab->tabid.'+\'',$tempArr[0]))."');";
// $end.="\nalert(temp);";
$end.="\neval(temp);";
$results.=$tempArr[1];
// die("\n\n".$end);
}
$ret .=str_replace("\n","",str_replace("'","\\'",str_replace("\\","\\\\",$results)));
$ret .="','NEWIDHERE',count".$tab->tabid.");";
if($this->params->get('enableConditions','0')==1){
$ret.="\ninitElements(document.getElementById('tbl_".$tab->tabid."'));";
$ret.="\napplyConditions(document.getElementById('tbl_".$tab->tabid."'));";
}
if($this->params->get('enableExtendedSelect','0')==1){
$sql="select params from #__comprofiler_plugin where element='extendedselect'";
$database->setQuery($sql);
$extselParams=$database->loadResult();
print("\n\n";
foreach($selects as $select){
$ret.=("\nenableExtendedSelect(count".$tab->tabid."+'".$select."[]');");
}
}
$ret .= $end;
$ret .="}";
$ret .='
';
return $ret;
}
function saveRegistrationTab($tab, $user, $ui, $postdata) {
$this->saveEditTab($tab, $user, $ui, $postdata);
}
function saveEditTab($tab, $user, $ui, $postdata) {
global $database;
$sql= "SELECT id FROM #__comprofiler_listtab_".$tab->tabid." WHERE userid= ". $user->id ;
$database->setQuery($sql);
$extIds = $database->loadResultArray();
$database->setQuery( "SELECT * FROM #__comprofiler_fields WHERE published=1 and tabid = ".$tab->tabid." and readonly=0" );
$rowFields = $database->loadObjectList();
$cbFields=new cbFields();
foreach($extIds as $extId){
$dataFound=false;
$rowExtras = new stdClass();
for($i=0, $n=count( $rowFields ); $i < $n; $i++) {
$field=cbGetEscaped($rowFields[$i]->name);
$value=null;
if(isset($_POST[$extId.$rowFields[$i]->name])){
$value=$cbFields->prepareFieldDataSave($rowFields[$i]->type,$rowFields[$i]->name,$_POST[$extId.$rowFields[$i]->name]);
if($value!=''){
$dataFound=true;
}
$rowExtras->$field=$value;
}
}
$rowExtras->id=$extId;
$rowExtras->userid=$user->id;
$rowExtras->tabid=$tab->tabid;
//If data is found, do UPDATE else do DELETE
if($dataFound){
$database->updateObject( '#__comprofiler_listtab_'.$tab->tabid, $rowExtras, 'id');
// die($database->stderr(true));
if($database->getErrorNum()==1054){
$this->_modifyColumns($tab->tabid); //Check if new fields have been added but are not in the table yet and updata the table
$database->updateObject( '#__comprofiler_listtab_'.$tab->tabid, $rowExtras, 'id');
}
}
else{
$sql = "DELETE FROM #__comprofiler_listtab_".$tab->tabid." WHERE id=".$extId;
$database->setQuery($sql);
if (!$database->query()) {
echo "\n";
}
// die($database->stderr(true));
}
}
//Updates and deletes processed this far. Let's do inserts next.
for ($newid=1; $newid<=20; $newid++){
$dataFound=false;
$rowExtras = new stdClass();
for($i=0, $n=count( $rowFields ); $i < $n; $i++) {
$field=cbGetEscaped($rowFields[$i]->name);
$value=null;
if(isset($_POST["new".$newid.$rowFields[$i]->name])){
$value=$cbFields->prepareFieldDataSave($rowFields[$i]->type,$rowFields[$i]->name,$_POST["new".$newid.$rowFields[$i]->name]);
if($value!='')
$dataFound=true;
}
$rowExtras->$field=$value;
}
$rowExtras->userid=$user->id;
$rowExtras->tabid=$tab->tabid;
//If data is found, do INSERT
if($dataFound){
$database->insertObject( '#__comprofiler_listtab_'.$tab->tabid, $rowExtras);
if($database->getErrorNum()==1054){
$this->_modifyColumns($tab->tabid); //Check if new fields have been added but are not in the table yet and update the table
$database->insertObject( '#__comprofiler_listtab_'.$tab->tabid, $rowExtras);
}
}
}
}
function loadTabList($name,$value,$control_name) {
global $database;
$database->setQuery("select tabid, title from #__comprofiler_tabs where pluginclass is null or pluginclass = 'listtab'");
$tabs = $database->loadObjectList();
$tabList = array();
$tabList[] = mosHTML::makeOption(-1,'none');
foreach ($tabs as $tab) {
$tabList[] = mosHTML::makeOption( $tab->tabid, $tab->title);
}
$valAsObj = (isset($value)&&$value!='') ?
array_map(create_function('$v', '$o=new stdClass(); $o->value=$v; return $o;'), explode("|*|", $value ))
:$this->_getSelectedTabs();
return moscomprofilerHTML::selectList( $tabList, $control_name .'['. $name .'][]', 'size="4" multiple="multiple"', 'value', 'text', $valAsObj, true );
}
function _getSelectedTabs(){
global $database;
$database->setQuery("select tabid, title from #__comprofiler_tabs where pluginclass = 'listtab'");
$tabs = $database->loadObjectList();
$tabList = array();
foreach ($tabs as $tab) {
$tabList[] = mosHTML::makeOption( $tab->tabid, null);
}
return $tabList;
}
function checkForConfigUpdates($a,$b,$c,$d){
global $database;
$database->setQuery("select count(id) from #__comprofiler_plugin where element='listtab' and params like '%listEnabledTabs%'");
$debug=$database->loadResult();
if($database->loadResult()==1){
//lets update the tabs
$tabsToUpdate = explode("|*|", $this->params->get('listEnabledTabs',''));
$pluginId=$this->id;
$modifyComprofiler = $this->params->get('modifyComprofiler','0');
$enableConditions = $this->params->get('enableConditions','0');
$showAsLists = $this->params->get('showAsLists','0');
$sql="UPDATE #__comprofiler_plugin SET params ='enableConditions=".
$enableConditions."\nmodifyComprofiler=".
$modifyComprofiler."\nshowAsLists=".$showAsLists."' where element='listtab'";
//debug echo ($sql."\n");
$database->SetQuery($sql);
if (!$database->query()) {
echo "\n";
}
$sql="UPDATE #__comprofiler_tabs SET pluginclass = null,".
" pluginid = null where pluginclass ='listtab'";
//debug echo ($sql."\n");
$database->SetQuery($sql);
if (!$database->query()) {
echo "\n";
}
foreach($tabsToUpdate as $tab){
$sql="CREATE TABLE IF NOT EXISTS `#__comprofiler_listtab_".$tab.
"` (`id` INT NOT NULL AUTO_INCREMENT ,`userid` INT NOT NULL ,".
"`tabid` INT NOT NULL ,PRIMARY KEY ( `id` )) TYPE = MYISAM ;";
//debug echo ($sql."\n");
$database->SetQuery($sql);
if (!$database->query()) {
echo "\n";
}
$sql="UPDATE #__comprofiler_tabs SET pluginclass ='listtab',".
" pluginid=".$pluginId." where tabid=".$tab;
//debug echo ($sql."\n");
$database->SetQuery($sql);
if (!$database->query()) {
echo "\n";
}
$this->_modifyColumns($tab);
}
//next we need to be sure that columns are moved back.
$sql="SELECT f.name, f.type, f.fieldid, f.tabid from #__comprofiler_fields f,".
" #__comprofiler_tabs t where f.tabid=t.tabid and".
" (t.pluginclass IS NULL OR t.pluginclass NOT LIKE 'listtab')";
$database->setQuery($sql);
$fieldList=$database->loadObjectList();
foreach($fieldList as $field){
$this->checkAndModifyField($field,'#__comprofiler','#__comprofiler_listtab_'.$field->tabid,$modifyComprofiler);
}
// die("debug");
}
}
function _modifyColumns($tab){
global $database;
$sql="SELECT name, type, fieldid from #__comprofiler_fields where tabid=".$tab;
//debug echo ($sql."\n");
//these must exist in the external table
$database->setQuery($sql);
$fieldList=$database->loadObjectList();
$modifyComprofiler = $this->params->get('modifyComprofiler','0');
foreach($fieldList as $field){
$this->checkAndModifyField($field,'#__comprofiler_listtab_'.$tab,'#__comprofiler',$modifyComprofiler);
}
}
function checkAndModifyField($field,$insertTo,$removeFrom,$deleteOriginal){
global $database;
$sql="SHOW COLUMNS FROM ".$insertTo." LIKE '".$field->name."'";
//debug echo ($sql."\n delete original=".$deleteOriginal);
$database->setQuery($sql);
$obj=$database->LoadResult();
if($obj==false or $obj == null or $obj==''){
SWITCH($field->type) {
CASE 'date':
$cType='DATE';
break;
CASE 'editorta':
CASE 'textarea':
CASE 'multiselect':
CASE 'multicheckbox':
$cType='MEDIUMTEXT';
break;
CASE 'checkbox':
$cType='TINYINT';
break;
default:
$cType='VARCHAR(255)';
break;
}
$name=$field->name;
$sql="ALTER TABLE `$insertTo` ADD `$name` $cType";
//debug echo ($sql."\n");
$database->setQuery($sql);
$database->query();
//Copy data from external table to comprofiler
if($insertTo=='#__comprofiler'){
//@todo: implement data copying
}
else{
//@todo: implement data copying
}
if($deleteOriginal==1){
$sql="ALTER TABLE `$removeFrom` DROP `$name`";
//debug echo ($sql."\n");
$database->setQuery($sql);
$database->query();
}
$sql="UPDATE #__comprofiler_fields SET `table`='".$insertTo."' WHERE fieldid=".$field->fieldid;
//debug echo ($sql."\n");
$database->setQuery($sql);
$database->query();
}
}
} // end class listTab.
function filterExtSel($var){
print "\ninside callback\n";
$ret=(strpos($var,"fields=")==0);
print $var." Qualifies:".$ret."\n";
return $ret;
}
?>