tableName)) { $adb->pquery('DELETE FROM '.$this->tableName .' WHERE userid = ?', array($userId)); } } function setFields($data) { if(!empty($data)) { foreach($data as $name => $value) { $this->fieldData[$name] = $value; } } } function save() { $adb = PearDatabase::getInstance(); if(count($this->fieldData) == 0) return; if(!Vtiger_Utils::CheckTable($this->tableName)) { Vtiger_Utils::CreateTable( $this->tableName, "(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, userid INT NOT NULL, entitytype VARCHAR(200) NOT NULL, crmid INT NOT NULL)", true); } $fieldNames = array_keys($this->fieldData); $fieldValues = array_values($this->fieldData); $adb->pquery('INSERT INTO '.$this->tableName.'('. implode(',',$fieldNames) .') VALUES ('. generateQuestionMarks($fieldValues) .')', array($fieldValues)); } function undo($moduleName, $userId) { $adb = PearDatabase::getInstance(); if(Vtiger_Utils::CheckTable($this->tableName)) { $result = $adb->pquery('UPDATE vtiger_crmentity SET deleted=1 WHERE crmid IN (SELECT crmid FROM '.$this->tableName .' WHERE userid = ? AND entitytype = ?)', array($userId, $moduleName)); return $adb->getAffectedRowCount($result); } } } ?>