public function submit_attach($file, $oryg, $data, $record) { if (!$oryg) { $this->submitted = true; return; } /* check extension */ $possible_extensions = array('jpg', 'jpeg', 'png'); $extension = strtolower(end(explode('.', $oryg))); if (!in_array($extension, $possible_extensions)) { echo __('Filename extension should be one of these (letter size doesn\'t matter): ') . implode(', ', $possible_extensions); return; } if ($file) { $local = $this->get_data_dir(); $filebase = md5($record['first_name'] . $record['last_name']) . $record['id']; $pattern = $local . $filebase; $i = 0; while (file_exists($pattern . $i . '.' . $extension)) { $i++; } $dest_file = $pattern . $i . '.' . $extension; $thumb = Utils_ImageCommon::create_thumb($file, 600, 600); @unlink($file); rename($thumb['thumb'], $dest_file); CRM_Contacts_PhotoCommon::add_photo($record['id'], $filebase . $i . '.' . $extension); } $this->submitted = true; }
public function download_template() { $ld = $this->get_data_dir() . 'list/'; if (!file_exists($ld)) { return $this->download_templates_list(); } if ($this->is_back()) { return false; } Base_ActionBarCommon::add('back', __('Back'), $this->create_back_href()); Base_ActionBarCommon::add('search', __('Update templates list'), $this->create_callback_href(array($this, 'download_templates_list'))); $m = $this->init_module(Utils_GenericBrowser::module_name(), null, 'new_templates'); $m->set_table_columns(array(array('name' => 'Name', 'search' => 1), array('name' => 'Version'), array('name' => 'Screenshot'), array('name' => 'Author', 'search' => 1), array('name' => 'Info', 'search' => 1), array('name' => 'Compatible'))); $content = scandir($ld); foreach ($content as $template_name) { if ($template_name == '.' || $template_name == '..') { continue; } $ini = parse_ini_file($ld . $template_name . '/info.ini'); $compatible = version_compare($ini['epesi_version'], EPESI_VERSION) <= 0; $installed = is_dir(DATA_DIR . '/Base_Theme/templates/' . $template_name); if ($installed) { $installed_ini = @parse_ini_file(DATA_DIR . '/Base_Theme/templates/' . $template_name . '/info.ini'); if (!$installed_ini) { $installed_ini = array('version' => 0); } } if (isset($ini['screenshot'])) { $th_big = Utils_ImageCommon::create_thumb($ld . $template_name . '/' . $ini['screenshot'], 640, 480); $thumb = '<a href="' . $th_big['thumb'] . '" rel="lyteshow">' . Utils_ImageCommon::get_thumb_html($ld . $template_name . '/' . $ini['screenshot'], 120, 120) . '</a>'; } else { $thumb = ''; } $r = $m->get_new_row(); $r->add_data($template_name, $ini['version'], $thumb, $ini['author'], $ini['info'], $compatible ? '<font color="green">yes</font>' : '<font color="red">NO</font> epesi ' . $ini['epesi_version'] . ' required'); if ($compatible && !$installed) { $r->add_action($this->create_callback_href(array($this, 'install_template'), $template_name), 'Install'); } if ($installed) { $r->add_action($this->create_callback_href(array($this, 'delete_template'), $template_name), 'Delete'); if ($ini['version'] > $installed_ini['version']) { $r->add_action($this->create_callback_href(array($this, 'update_template'), $template_name), 'Update'); } } } $this->display_module($m, array(true), 'automatic_display'); return true; }