Ejemplo n.º 1
0
 /**
  * This is function is called by the form object to get the DataSource's
  * form snippet. It should add all fields necesarry to get the data
  * uploaded to the temporary table in the DB.
  *
  * @param CRM_Core_Form $form
  *
  * @return void
  *   (operates directly on form argument)
  */
 public function buildQuickForm(&$form)
 {
     $form->add('hidden', 'hidden_dataSource', 'CRM_Import_DataSource_CSV');
     $config = CRM_Core_Config::singleton();
     $uploadFileSize = CRM_Utils_Number::formatUnitSize($config->maxFileSize . 'm', TRUE);
     $uploadSize = round($uploadFileSize / (1024 * 1024), 2);
     $form->assign('uploadSize', $uploadSize);
     $form->add('File', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
     $form->setMaxFileSize($uploadFileSize);
     $form->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize);
     $form->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File');
     $form->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
     $form->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers'));
 }
Ejemplo n.º 2
0
 /**
  * @param CRM_Core_Form $form
  * @param string $entityTable
  * @param int $entityID
  * @param null $numAttachments
  * @param bool $ajaxDelete
  */
 public static function buildAttachment(&$form, $entityTable, $entityID = NULL, $numAttachments = NULL, $ajaxDelete = FALSE)
 {
     if (!$numAttachments) {
         $numAttachments = Civi::settings()->get('max_attachments');
     }
     // Assign maxAttachments count to template for help message
     $form->assign('maxAttachments', $numAttachments);
     $config = CRM_Core_Config::singleton();
     // set default max file size as 2MB
     $maxFileSize = $config->maxFileSize ? $config->maxFileSize : 2;
     $currentAttachmentInfo = self::getEntityFile($entityTable, $entityID, TRUE);
     $totalAttachments = 0;
     if ($currentAttachmentInfo) {
         $totalAttachments = count($currentAttachmentInfo);
         $form->add('checkbox', 'is_delete_attachment', ts('Delete All Attachment(s)'));
         $form->assign('currentAttachmentInfo', $currentAttachmentInfo);
     } else {
         $form->assign('currentAttachmentInfo', NULL);
     }
     if ($totalAttachments) {
         if ($totalAttachments >= $numAttachments) {
             $numAttachments = 0;
         } else {
             $numAttachments -= $totalAttachments;
         }
     }
     $form->assign('numAttachments', $numAttachments);
     CRM_Core_BAO_Tag::getTags('civicrm_file', $tags, NULL, '  ', TRUE);
     // get tagset info
     $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_file');
     // add attachments
     for ($i = 1; $i <= $numAttachments; $i++) {
         $form->addElement('file', "attachFile_{$i}", ts('Attach File'), 'size=30 maxlength=60');
         $form->addUploadElement("attachFile_{$i}");
         $form->setMaxFileSize($maxFileSize * 1024 * 1024);
         $form->addRule("attachFile_{$i}", ts('File size should be less than %1 MByte(s)', array(1 => $maxFileSize)), 'maxfilesize', $maxFileSize * 1024 * 1024);
         $form->addElement('text', "attachDesc_{$i}", NULL, array('size' => 40, 'maxlength' => 255, 'placeholder' => ts('Description')));
         if (!empty($tags)) {
             $form->add('select', "tag_{$i}", ts('Tags'), $tags, FALSE, array('id' => "tags_{$i}", 'multiple' => 'multiple', 'class' => 'huge crm-select2', 'placeholder' => ts('- none -')));
         }
         CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_file', NULL, FALSE, TRUE, "file_taglist_{$i}");
     }
 }