Exemple #1
0
 /**
  * Inserts the part into the project.
  *
  * @param EcrProjectBase $easyProject The project.
  * @param array $options Insert options.
  * @param EcrLogger $logger The EcrLogger.
  *
  * @return boolean
  */
 public function insert(EcrProjectBase $easyProject, $options, EcrLogger $logger)
 {
     $easyProject->addSubstitute('ECR_SUBPACKAGE', 'Models');
     return $easyProject->insertPart($options, $logger);
 }
Exemple #2
0
 /**
  * Inserts the part into the project.
  *
  * @param EcrProjectBase $EasyProject The project.
  * @param array $options Insert options.
  * @param EcrLogger $logger The EcrLogger.
  *
  * @return boolean
  */
 public function insert(EcrProjectBase $EasyProject, $options, EcrLogger $logger)
 {
     $input = JFactory::getApplication()->input;
     $this->_options = $options;
     $EasyProject->addSubstitute('ECR_SUBPACKAGE', 'Views');
     $element_name = $input->get('element_name');
     $table_name = $input->get('table_name');
     $req_table_fields = $input->get('table_fields', array(), 'array');
     $req_table_fields_types = $input->get('table_fields_types', array(), 'array');
     if (!$table_name) {
         $table_name = $element_name;
     }
     if (!$table_name) {
         $table_name = $element_name;
         JFactory::getApplication()->enqueueMessage(jgettext('No table given'), 'error');
         return false;
     }
     $table_name = strtolower($table_name);
     $db = JFactory::getDBO();
     $prefix = $db->getPrefix();
     $fields = $db->getTableFields($prefix . $table_name);
     $tableFields = array();
     $table_vars = '';
     if (count($fields)) {
         $tableFields = $fields[$prefix . $table_name];
     }
     /*
      * Add substitutes
      */
     $EasyProject->addSubstitute('ECR_ELEMENT_NAME', $element_name);
     $EasyProject->addSubstitute('_ECR_LOWER_ELEMENT_NAME_', strtolower($element_name));
     $EasyProject->addSubstitute('_ECR_TABLE_NAME_', $table_name);
     /*
      * Add manual substitutes
      */
     //        $substitutes = array();
     //        foreach($this->patterns as $pKey => $pReplacement)
     //        {
     //            $substitutes[$pKey] = '';
     //        }//foreach
     $code = '';
     $acFields = array();
     foreach ($req_table_fields as $field) {
         $f = new stdClass();
         $f->name = $field;
         $f->type = $req_table_fields_types[$field];
         $code .= str_replace('_ECR_KEY_', $f->name, $this->fieldsOptions[$f->type]);
         $acFields[] = $f;
         //            $acOptions[$field] = array();
         //            $acOptions[$field]['type'] = $req_table_fields_types[$field];
     }
     //foreach
     //        foreach($tableFields as $key => $value)
     //        {
     //            if( ! in_array($key, $req_table_fields)) { continue; }
     //
     //            foreach($this->patterns as $pKey => $pReplacement)
     //            {
     //                $substitutes[$pKey] .= str_replace('##ECR_KEY##', $key, $pReplacement);
     //            }//foreach
     //            $i ++;
     //        }//foreach
     /*       $substitutes['##ECR_VIEW1_TMPL1_THS##'] .= '    <?php $coloumnCount += '.$i.'; ?>'.NL;
     */
     $AutoCode = new EcrProjectAutocode($this->group, $this->name, $table_name, $this->_scope);
     //        $AutoCode->group = $this->group;
     //        $AutoCode->name = $this->name;
     //
     //        $AutoCode->element = $table_name;
     //        $AutoCode->scope = $this->_scope;
     $AutoCode->options = array();
     //$acOptions;
     //        foreach($substitutes as $key => $value)
     //        {
     $key = '##ECR_OPTIONS##';
     $AutoCode->fields[$key] = $acFields;
     //array();
     $AutoCode->codes[$key] = $AutoCode->enclose($code, $key, true);
     $EasyProject->addSubstitute($key, $AutoCode->enclose($code, $key, true));
     //        }
     //        foreach($substitutes as $key => $value)
     //        {
     //            $EcrProject->addSubstitute($key, $AutoCode->enclose($code, $key, true));
     //        }
     $EasyProject->addAutoCode($AutoCode, $this->key);
     return $EasyProject->insertPart($options, $logger);
 }
Exemple #3
0
 /**
  * Inserts the AutoCode into the project.
  *
  * @param EcrProjectBase $project The project.
  * @param array $options Insert options.
  * @param EcrLogger $logger EcrLogger.
  *
  * @return boolean
  */
 public function insert(EcrProjectBase $project, $options, EcrLogger $logger)
 {
     $input = JFactory::getApplication()->input;
     $table_name = $input->get('element');
     $var_scope = $input->get('var_scope');
     $element_scope = $input->get('element_scope');
     if (!$table_name) {
         JFactory::getApplication()->enqueueMessage(jgettext('No table given'), 'error');
         return false;
     }
     $db = JFactory::getDBO();
     $prefix = $db->getPrefix();
     $fields = $db->getTableFields($prefix . $table_name);
     $table_vars = '';
     $autoCodeFields = array();
     $reqFields = $input->get('field', array(), 'array');
     if (count($fields)) {
         foreach ($fields[$prefix . $table_name] as $name => $type) {
             $reqField = $reqFields[$name];
             if (isset($project->autoCodes[$this->key]->fields[$this->key . '.var'][$name])) {
                 $field = $project->autoCodes[$this->key]->fields[$this->key . '.var'][$name];
                 $field->label = $reqField['label'];
             } else {
                 $field = new EcrTableField();
                 $field->name = $name;
                 $field->label = $name;
                 $field->type = $type;
             }
             $autoCodeFields[] = $field;
             $adds = array($field->label);
             $table_vars .= EcrTableHelper::formatTableVar($name, $type, $adds, $var_scope);
         }
         //foreach
     }
     $AutoCode = new EcrProjectAutocode($this->group, $this->name, $table_name, $element_scope);
     $AutoCode->options = array();
     $AutoCode->options['varscope'] = $var_scope;
     $AutoCode->fields[$AutoCode->getKey() . '.var'] = $autoCodeFields;
     $AutoCode->codes[$AutoCode->getKey() . '.var'] = $AutoCode->enclose($table_vars, $AutoCode->getKey() . '.var');
     $project->addAutoCode($AutoCode);
     /*
      * Add substitutes
      *
      * Define keys that will be substitutes in the code
      */
     $project->addSubstitute('ECR_SUBPACKAGE', 'Tables');
     $project->addSubstitute('_ECR_TABLE_NAME_', $table_name);
     foreach ($AutoCode->codes as $key => $code) {
         $project->addSubstitute($key, $code);
     }
     //foreach
     /* Insert the part to your project and return the results */
     return $project->insertPart($options, $logger);
 }
Exemple #4
0
 /**
  * Inserts the AutoCode into the project.
  *
  * @param EcrProjectBase $project The project.
  * @param array $options Insert options.
  * @param EcrLogger $logger The EcrLogger.
  *
  * @return boolean
  */
 public function insert(EcrProjectBase $project, $options, EcrLogger $logger)
 {
     JFactory::getApplication()->enqueueMessage(__METHOD__ . ' not finished', 'error');
     $input = JFactory::getApplication()->input;
     $table_name = $input->get('element');
     $element_scope = $input->get('element_scope');
     if (!$table_name) {
         JFactory::getApplication()->enqueueMessage(jgettext('No table given'), 'error');
         return false;
     }
     $fields = EcrTableHelper::getTableColumns($table_name);
     $reqFields = $input->get('field', array(), 'array');
     $headers = '';
     $cells = '';
     $tags = array('<!--', '-->');
     $indent = '            ';
     if (!count($fields)) {
         JFactory::getApplication()->enqueueMessage('No table fields found', 'error');
         return false;
     }
     foreach ($fields as $name => $field) {
         $reqFieldHeader = $reqFields['header'][$name];
         $reqFieldCell = $reqFields['cell'][$name];
         if (isset($project->autoCodes[$this->key]->fields[$this->key . '.header'][$name])) {
             $fieldHeader = $project->autoCodes[$this->key]->fields[$this->key . '.header'][$name];
             $fieldHeader->label = $reqFieldHeader['label'];
         } else {
             $fieldHeader = new EcrTableField();
             $fieldHeader->name = $name;
             $fieldHeader->label = $name;
         }
         if (isset($project->autoCodes[$this->key]->fields[$this->key . '.cell'][$name])) {
             $fieldCell = $project->autoCodes[$this->key]->fields[$this->key . '.cell'][$name];
         } else {
             $fieldCell = new EcrTableField();
             $fieldCell->name = $name;
         }
         $fieldHeader->display = $reqFieldHeader['display'];
         $fieldHeader->width = $reqFieldHeader['width'];
         //-- Display value for cells is the same as for headers
         $fieldCell->display = $reqFieldHeader['display'];
         $autoCodeFieldsHeader[] = $fieldHeader;
         $autoCodeFieldsCell[] = $fieldCell;
         $headers .= $this->getCode('header', $fieldHeader, $indent);
         $cells .= $this->getCode('cell', $fieldCell, $indent);
     }
     //foreach
     $this->fields[$this->key . '.header'] = $autoCodeFieldsHeader;
     $this->codes[$this->key . '.header'] = $this->enclose($headers, $this->key . '.header', true);
     $this->fields[$this->key . '.cell'] = $autoCodeFieldsCell;
     $this->codes[$this->key . '.cell'] = $this->enclose($cells, $this->key . '.cell', true);
     $project->addAutoCode($this);
     /*
      * Add substitutes
      *
      * Define keys that will be substitutes in the code
      */
     $project->addSubstitute('ECR_SUBPACKAGE', 'Views');
     $project->addSubstitute('_ECR_TABLE_NAME_', $table_name);
     foreach ($this->codes as $key => $code) {
         $project->addSubstitute($tags[0] . $key . $tags[1], $code);
     }
     //foreach
     /* Insert the part to your project and return the results */
     return $project->insertPart($options, $logger);
 }
Exemple #5
0
 /**
  * Process install files.
  *
  * @throws EcrExceptionZiper
  *
  * @return EcrProjectZiper
  */
 private function processInstall()
 {
     $installFiles = EcrProjectHelper::findInstallFiles($this->project);
     if (0 == count($installFiles['php'])) {
         return $this;
     }
     $srcDir = $this->temp_dir . DS . 'admin';
     $destDir = $this->temp_dir . DS . 'install';
     //-- Create 'install' folder in temp dir
     JFolder::create($destDir);
     //-- Copy install files from 'admin' to 'temp'
     foreach ($installFiles['php'] as $file) {
         $srcPath = $srcDir;
         $srcPath .= $file->folder ? DS . $file->folder : '';
         $srcPath .= DS . $file->name;
         $destPath = $destDir;
         if ($file->folder == 'install') {
             $folder = '';
         } else {
             $folder = str_replace('install' . DS, '', $file->folder);
         }
         if ($folder) {
             $destPath .= DS . $folder;
             //-- Create the folder
             JFolder::create($destPath);
         }
         if (JFile::copy($srcPath, $destPath . DS . $file->name)) {
             $this->logger->log('COPY INSTALL FILE<br />SRC: ' . $srcPath . '<br />DST: ' . $destPath . DS . $file->name);
         } else {
             $this->logger->log('COPY INSTALL FILE<br />SRC: ' . $srcPath . '<br />DST: ' . $destPath . DS . $file->name, 'ERROR copy file');
             continue;
         }
         if (0 != strpos($file->name, 'install')) {
             continue;
         }
         if ($this->buildopts['createMD5']) {
             $format = 'po' == $this->project->langFormat ? '.po' : '';
             $compressed = $this->buildopts['createMD5Compressed'] ? '_compressed' : '';
             $fileContents = JFile::read(ECRPATH_EXTENSIONTEMPLATES . DS . 'std' . DS . 'md5check' . $compressed . $format . '.php');
             $fileContents = str_replace('<?php', '', $fileContents);
             $this->project->addSubstitute('##ECR_MD5CHECK_FNC##', $fileContents);
             $fileContents = JFile::read(ECRPATH_EXTENSIONTEMPLATES . DS . 'std' . DS . 'md5check_call' . $format . '.php');
             $fileContents = str_replace('<?php', '', $fileContents);
             $this->project->addSubstitute('##ECR_MD5CHECK##', $fileContents);
             $this->project->addSubstitute('ECR_COM_COM_NAME', $this->project->comName);
             $fileContents = JFile::read($destPath . DS . $file->name);
             $fileContents = $this->project->substitute($fileContents);
         } else {
             $this->project->addSubstitute('##ECR_MD5CHECK_FNC##', '');
             $this->project->addSubstitute('##ECR_MD5CHECK##', '');
             $fileContents = JFile::read($destPath . DS . $file->name);
             $fileContents = $this->project->substitute($fileContents);
         }
         if (JFile::write($destPath . DS . $file->name, $fileContents)) {
             $this->logger->logFileWrite('', 'install/install.php', $fileContents);
         } else {
             $this->logger->log('Failed to add MD5 install check routine to install.php', 'error');
         }
     }
     //-- Delete install files from 'admin'
     foreach ($installFiles['php'] as $file) {
         $srcPath = $srcDir;
         $srcPath .= $file->folder ? DS . $file->folder : '';
         $srcPath .= DS . $file->name;
         if (false == JFile::delete($srcPath)) {
             throw new EcrExceptionZiper(__METHOD__ . ' - Delete install file failed: ' . $srcPath);
         }
         $this->logger->log('INSTALL FILE DELETED<br />SRC: ' . $srcPath);
     }
     return $this;
 }
Exemple #6
0
 /**
  * Inserts the AutoCode into the project.
  *
  * @param EcrProjectBase $project The project.
  * @param array $options Insert options.
  * @param EcrLogger $logger EcrLogger.
  *
  * @return boolean
  */
 public function insert(EcrProjectBase $project, $options, EcrLogger $logger)
 {
     $input = JFactory::getApplication()->input;
     $table_name = $input->get('element');
     $element_scope = $input->get('element_scope');
     $element = 'row';
     if (!$table_name) {
         JFactory::getApplication()->enqueueMessage(jgettext('No table given'), 'error');
         return false;
     }
     $table = new EcrTable($table_name);
     $fields = EcrTableHelper::getTableColumns($table_name);
     $reqFields = $input->get('field', array(), 'array');
     $rows = '';
     $tags = array('<!--', '-->');
     $indent = '            ';
     if (!count($fields)) {
         JFactory::getApplication()->enqueueMessage('No table fields found', 'error');
         return false;
     }
     foreach ($fields as $name => $field) {
         $reqFieldHeader = $reqFields[$name];
         if (isset($project->autoCodes[$this->key]->fields[$this->key . '.' . $element][$name])) {
             $fieldHeader = $project->autoCodes[$this->key]->fields[$this->key . '.' . $element][$name];
         } else {
             $fieldHeader = new EcrTableField();
             $fieldHeader->name = $name;
         }
         $fieldHeader->label = $reqFieldHeader['label'];
         $fieldHeader->inputType = $reqFieldHeader['input_type'];
         $autoCodeFieldsHeader[] = $fieldHeader;
         $table->addField($fieldHeader);
     }
     //foreach
     $rows .= $this->getCode($element, $table, $indent);
     $this->fields[$this->key . '.' . $element] = $autoCodeFieldsHeader;
     $this->codes[$this->key . '.' . $element] = $this->enclose($rows, $this->key . '.' . $element);
     $project->addAutoCode($this);
     /*
      * Add substitutes
      *
      * Define keys that will be substitutes in the code
      */
     $project->addSubstitute('ECR_SUBPACKAGE', 'Views');
     $project->addSubstitute('_ECR_TABLE_NAME_', $table_name);
     foreach ($this->codes as $key => $code) {
         $project->addSubstitute($tags[0] . $key . $tags[1], $code);
     }
     //foreach
     /* Insert the part to your project and return the results */
     return $project->insertPart($options, $logger);
 }
Exemple #7
0
 /**
  * Inserts the part into the project.
  *
  * @param EcrProjectBase $project The project.
  * @param array $options Insert options.
  * @param EcrLogger $logger The EcrLogger.
  *
  * @return boolean
  */
 public function insert(EcrProjectBase $project, $options, EcrLogger $logger)
 {
     $input = JFactory::getApplication()->input;
     $element_name = $input->get('element_name');
     $table_name = $input->get('table_name');
     $req_table_fields = $input->get('table_fields', array(), 'array');
     $req_table_fields_edits = $input->get('table_fields_edits', array(), 'array');
     $req_table_fields_types = $input->get('table_fields_types', array(), 'array');
     if (!$table_name) {
         JFactory::getApplication()->enqueueMessage(jgettext('No table given'), 'error');
         return false;
     }
     $db = JFactory::getDBO();
     $prefix = $db->getPrefix();
     $fields = $db->getTableFields($prefix . $table_name);
     $tableFields = array();
     $table_vars = '';
     if (count($fields)) {
         $tableFields = $fields[$prefix . $table_name];
         foreach ($tableFields as $key => $value) {
             if (!in_array($key, $req_table_fields)) {
                 continue;
             }
             $table_vars .= EcrTableHelper::formatTableVar($key, $value);
         }
         //foreach
     }
     /*
      * Add substitutes
      */
     $project->addSubstitute('ECR_ELEMENT_NAME', $element_name);
     $project->addSubstitute('_ECR_LOWER_ELEMENT_NAME_', strtolower($element_name));
     $project->addSubstitute('_ECR_TABLE_NAME_', $table_name);
     $project->addSubstitute('##ECR_TABLE_VARS##', $table_vars);
     /*
      * Read part options files
      */
     $files = JFolder::files($options->pathSource . DS . 'options', '.', true, true);
     foreach ($files as $file) {
         $fileContents = JFile::read($file);
         if (strpos($fileContents, '<?php') === 0) {
             $fileContents = substr($fileContents, 6);
         }
         $project->substitute($fileContents);
         $project->addSubstitute('##' . strtoupper(JFile::stripExt(JFile::getName($file))) . '##', $fileContents);
     }
     //foreach
     /*
      * Add manual substitutes
      */
     $substitutes['##ECR_VIEW1_TMPL1_THS##'] = '?>';
     $substitutes['##ECR_VIEW1_TMPL1_TDS##'] = '?>';
     $substitutes['##ECR_VIEW2_TMPL1_OPTION2##'] = '?>';
     $i = 0;
     foreach ($tableFields as $key => $value) {
         if (!in_array($key, $req_table_fields)) {
             continue;
         }
         $substitutes['##ECR_VIEW1_TMPL1_THS##'] .= '    <th>' . NL;
         $substitutes['##ECR_VIEW1_TMPL1_THS##'] .= "        <?php echo JHTML::_('grid.sort', '" . $key . "', '" . $key . "', \$this->lists['order_Dir'], \$this->lists['order']);?>" . NL;
         $substitutes['##ECR_VIEW1_TMPL1_THS##'] .= '    </th>' . NL;
         $substitutes['##ECR_VIEW1_TMPL1_TDS##'] .= '    <td>' . NL;
         $substitutes['##ECR_VIEW1_TMPL1_TDS##'] .= '        <?php echo $row->' . $key . '; ?>' . NL;
         $substitutes['##ECR_VIEW1_TMPL1_TDS##'] .= '    </td>' . NL;
         if (in_array($key, $req_table_fields_edits)) {
             $s = $project->getSubstitute('##ECR_VIEW2_TMPL1_OPTION2VAL##');
             $s = str_replace('_ECR_FIELDVALUE_1_', $key, $s);
             $s = str_replace('_ECR_FIELDVALUE_2_', $req_table_fields_types[$key], $s);
             $substitutes['##ECR_VIEW2_TMPL1_OPTION2##'] .= $s;
         }
         $i++;
     }
     //foreach
     $substitutes['##ECR_VIEW1_TMPL1_THS##'] .= '    <?php $coloumnCount += ' . $i . '; ?>' . NL;
     $substitutes['##ECR_VIEW1_TMPL1_THS##'] .= '    <?php ' . NL;
     $substitutes['##ECR_VIEW1_TMPL1_TDS##'] .= '    <?php ' . NL;
     $substitutes['##ECR_VIEW2_TMPL1_OPTION2##'] .= '    <?php ' . NL;
     foreach ($substitutes as $key => $value) {
         $project->addSubstitute($key, $value);
     }
     //foreach
     /*
      * Remove options
      */
     if (!in_array('ordering', $req_table_fields)) {
         $project->addSubstitute('##ECR_CONTROLLER1_OPTION1##', '');
     }
     if (!in_array('published', $req_table_fields)) {
     }
     $project->addSubstitute('ECR_SUBPACKAGE', 'Tables');
     $input->set('element_scope', 'admin');
     if (!$project->insertPart($options, $logger)) {
         return false;
     }
     /*
      * Create menu link
      */
     if ($input->get('create_menu_link', false)) {
         $link = 'option=' . $options->ecr_project . '&view=' . strtolower($element_name) . $project->listPostfix . '&controller=' . strtolower($element_name) . $project->listPostfix;
         if (!$project->addSubmenuEntry($element_name, $link)) {
             JFactory::getApplication()->enqueueMessage(jgettext('Unable to create menu link'), 'error');
             return false;
         }
     }
     return true;
 }
Exemple #8
0
 /**
  * Inserts the part into the project.
  *
  * @param EcrProjectBase $EcrProject The project.
  * @param array $options Insert options.
  * @param EcrLogger $logger The EcrLogger.
  *
  * @return boolean
  */
 public function insert(EcrProjectBase $EcrProject, $options, EcrLogger $logger)
 {
     $input = JFactory::getApplication()->input;
     $EcrProject->addSubstitute('ECR_SUBPACKAGE', 'Models');
     $element_name = $input->get('element');
     $element_scope = $input->get('element_scope');
     $table_name = $input->get('table_name');
     if (!$table_name) {
         $table_name = $element_name;
     }
     $req_table_fields = $input->get('table_fields', array(), 'array');
     if (!$table_name) {
         JFactory::getApplication()->enqueueMessage(jgettext('No table given'), 'error');
         return false;
     }
     $db = JFactory::getDBO();
     $prefix = $db->getPrefix();
     $fields = $db->getTableFields($prefix . $table_name);
     $tableFields = array();
     $table_vars = '';
     if (count($fields)) {
         $tableFields = $fields[$prefix . $table_name];
     }
     /*
      * Add substitutes
      */
     $EcrProject->addSubstitute('ECR_ELEMENT_NAME', $element_name);
     $EcrProject->addSubstitute('_ECR_LOWER_ELEMENT_NAME_', strtolower($element_name));
     $EcrProject->addSubstitute('_ECR_TABLE_NAME_', $table_name);
     /*
      * Add manual substitutes
      */
     $substitutes = array();
     foreach ($this->patterns as $pKey => $pReplacement) {
         $substitutes[$pKey] = '';
     }
     //foreach
     $i = 0;
     foreach ($tableFields as $key => $value) {
         if (!in_array($key, $req_table_fields)) {
             continue;
         }
         foreach ($this->patterns as $pKey => $pReplacement) {
             $substitutes[$pKey] .= str_replace('##ECR_KEY##', $key, $pReplacement);
         }
         //foreach
         $i++;
     }
     //foreach
     $substitutes['##ECR_VIEW1_TMPL1_THS##'] .= '    <?php $coloumnCount += ' . $i . '; ?>' . NL;
     $AutoCode = new EcrProjectAutocode($this->group, $this->name, $table_name, $element_scope);
     $AutoCode->options = array();
     foreach ($substitutes as $key => $value) {
         $AutoCode->fields[$key] = $req_table_fields;
         //array();//$autoCodeFields;
         $AutoCode->codes[$key] = $AutoCode->enclose($value, $key, true);
         $EcrProject->addSubstitute($key, $AutoCode->enclose($value, $key, true));
     }
     //foreach
     $EcrProject->addAutoCode($AutoCode, $this->key);
     return $EcrProject->insertPart($options, $logger);
 }
Exemple #9
0
 /**
  * Inserts the part into the project.
  *
  * @param EcrProjectBase $project The project.
  * @param array $options Insert options.
  * @param EcrLogger $logger The EcrLogger.
  *
  * @return boolean
  */
 public function insert(EcrProjectBase $project, $options, EcrLogger $logger)
 {
     $project->addSubstitute('ECR_SUBPACKAGE', 'Installer');
     JFactory::getApplication()->input->set('element_scope', 'admin');
     return $project->insertPart($options, $logger);
 }
Exemple #10
0
 /**
  * Inserts the part into the project.
  *
  * @param EcrProjectBase $project The project.
  * @param array $options Insert options.
  * @param EcrLogger $logger The EcrLogger.
  *
  * @return boolean
  */
 public function insert(EcrProjectBase $project, $options, EcrLogger $logger)
 {
     $input = JFactory::getApplication()->input;
     $table_name = $input->get('element');
     $var_scope = $input->get('var_scope');
     $element_scope = $input->get('element_scope');
     if (!$table_name) {
         JFactory::getApplication()->enqueueMessage(jgettext('No table given'), 'error');
         return false;
     }
     $db = JFactory::getDBO();
     $prefix = $db->getPrefix();
     $fields = $db->getTableFields($prefix . $table_name);
     $table_vars = '';
     $autoCodeFields = array();
     if (count($fields)) {
         foreach ($fields[$prefix . $table_name] as $key => $value) {
             $table_vars .= $this->formatTableVar($key, $value, array(), $var_scope);
             $autoCodeFields[] = $key;
         }
         //foreach
     }
     $AutoCode = new EcrProjectAutocode($this->group, $this->name, $table_name, $element_scope);
     $AutoCode->options = array();
     $AutoCode->options['varScope'] = $var_scope;
     $AutoCode->fields['##ECR_TABLE_VARS##'] = array();
     //$autoCodeFields;
     $AutoCode->codes['##ECR_TABLE_VARS##'] = $AutoCode->enclose($table_vars, '##ECR_TABLE_VARS##');
     $AutoCode->fields['##ECR_FIELD_1##'] = array();
     $AutoCode->codes['##ECR_FIELD_1##'] = $AutoCode->enclose($this->formatTableVar('db', 'Database object', array(), $var_scope), '##ECR_FIELD_1##');
     $project->addAutoCode($AutoCode, $this->key);
     /*
      * Add substitutes
      *
      * Define keys that will be substitutes in the code
      */
     $project->addSubstitute('ECR_SUBPACKAGE', 'Tables');
     $project->addSubstitute('_ECR_TABLE_NAME_', $table_name);
     foreach ($AutoCode->codes as $key => $code) {
         $project->addSubstitute($key, $code);
     }
     //foreach
     /* Insert the part to your project and return the results */
     return $project->insertPart($options, $logger);
 }