Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1572

Přidáno uživatelem David Raška před více než 12 roky(ů)

Upravy:
- Pridan import a export sablon zarizeni

Zobrazit rozdíly:

freenetis/branches/testing/media/css/style.css
height: 14px;
}
.status_icon {
vertical-align: middle;
padding-right: .5em;
padding-bottom: .5em;
}
freenetis/branches/testing/application/i18n/cs_CZ/texts.php
'backup informations have been successfully set' => 'Informace o zálohování byly úspěšně přidány',
'backup informations have been successfully updated' => 'Informace o zálohování byly úspěšně aktualizovány',
'backup name' => 'Jméno zálohy',
'bad' => 'Chybné',
'bad entrance date' => 'Chybný datum vstupu.',
'bad format' => 'Špatný formát',
'bad icq format' => 'Špatný formát ICQ.',
......
'error - cant change password' => 'Chyba - nelze změnit heslo.',
'error - cant change limit' => 'Chyba - nelze změnit limit.',
'error - cant parse invoice' => 'Chyba - nelze parsovat fakturu.',
'error - can\'t read file' => 'Chyba - nelze přečíst soubor.',
'error - cant change voicemail' => 'Chyba - nelze změnit hlasovou schránku.',
'error - cant remove interface' => 'Chyba - nelze odstranit rozhraní.',
'error - cant remove vlan' => 'Chyba - nelze odstranit vlan.',
......
'executive counsil' => 'Správní rada',
'expenditure-earning' => 'Výdej-Příjem',
'expenses' => 'Výdaje',
'export device templates' => 'Export šablon zařízení',
'export of device' => 'Export zařízení',
'export of registration' => 'Export přihlášky',
'export to xls' => 'Exportovat do XLS',
......
'import has failed' => 'Import selhal.',
'import new invoice' => 'Import nové faktury',
'import private contact' => 'Importovat soukromé kontakty',
'import device templates' => 'Import šablon zařízení',
'import contact from server funanbol' => 'Importovat kontakty ze serveru Funanbol',
'import results' => 'Výsledky importu',
'import invoice' => 'Importovat fakturu',
'imported contacts' => 'Importované kontakty',
'imported' => 'Importováno',
'in' => 'v',
'in normal' => 'v normálu',
'in hours' => 'V hodinách',
......
'since' => 'Od',
'single choice' => 'Jediná volba',
'sixth-degree certified engineers' => 'Certifikování technici šestého stupně',
'skipped' => 'Přeskočeno',
'smokeping menu parent' => 'Rodič v menu smokepingu',
'smokeping monitoring' => 'Monitorování smokepingem',
'smokeping record has been successfully added' => 'Záznam smokepingu byl úspěšně přidán',
......
'update' => 'Aktualizovat',
'updated' => 'Upraveno',
'upload bank transfers listing' => 'Nahrát bankovní výpis',
'upload device templates' => 'Nahrát šablony zařízení',
'url' => 'URL',
'url addresses without index' => 'URL adresy bez index.php.',
'url settings' => 'Nastavení URL',
freenetis/branches/testing/application/helpers/download.php
$mime = 'application/octet-stream';
// Generate the server headers
header('Content-Type: '.$mime);
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Content-Length: '.$filesize);
header('Pragma: no-cache');
@header('Content-Type: '.$mime);
@header('Content-Disposition: attachment; filename="'.$filename.'"');
@header('Content-Transfer-Encoding: binary');
@header('Expires: 0');
@header('Content-Length: '.$filesize);
@header('Pragma: no-cache');
if (isset($filepath))
{
freenetis/branches/testing/application/controllers/device_templates.php
if ($this->acl_check_new('Devices_Controller', 'devices'))
{
$grid->add_new_button('device_templates/add', 'Add new template');
$grid->add_new_button('device_templates/import_from_file', 'Import device templates');
$grid->add_new_button('device_templates/export_to_json', 'Export device templates');
}
$grid->field('id')
......
}
/**
* Function shows upload dialog
*
* @author David Raška
*/
public function import_from_file()
{
// check acess
if (!$this->acl_check_view('Devices_Controller', 'devices'))
{
Controller::error(ACCESS);
}
$upload_form = new Forge();
$upload_form->upload('file')
->label('File')
->new_name('device_templates.json');
$upload_form->submit('Send');
$headline = __('Upload device templates');
// bread crumbs
$breadcrumbs = breadcrumbs::add()
->link('device_templates/show_all', 'Device templates',
$this->acl_check_view('Devices_Controller', 'devices'))
->disable_translation()
->text($headline)
->html();
if ($upload_form->validate())
{
$form_data = $upload_form->as_array(FALSE);
//load data from uploaded file
$handle = @fopen($form_data['file'], 'r');
$data = stream_get_contents($handle);
@fclose($handle);
//get array
$data = json_decode($data);
if ($data)
{
$imported = 0;
$skipped = 0;
$bad = 0;
// model
$device_templates = new Device_template_Model();
foreach ($data AS $template)
{
if (
!isset($template->name) ||
!isset($template->enum_type_id) ||
!isset($template->values) ||
!isset($template->default)
)
{
$bad++;
continue;
}
if (ORM::factory('device_template')
->where(array
(
'name' => $template->name,
'enum_type_id' => $template->enum_type_id
))
->count_all())
{
//Device template already exist
$skipped++;
}
else
{
$device_templates->transaction_start();
try
{
//New device template
$device_template_model = new Device_template_Model();
$device_template_model->name = $template->name;
$device_template_model->enum_type_id = $template->enum_type_id;
$device_template_model->values = json_encode($template->values);
$device_template_model->default = $template->default;
$device_template_model->save();
// remove old defauts
if ($template->default)
{
$tdefaults = $device_template_model->where(array
(
'id <>' => $device_template_model->id,
'enum_type_id' => $device_template_model->enum_type_id,
'default' => 1
))->find_all();
foreach ($tdefaults as $tdefault)
{
$tdefault->default = 0;
$tdefault->save();
}
}
$device_templates->transaction_commit();
$imported++;
}
catch (Exception $e)
{
$device_templates->transaction_rollback();
$bad++;
}
}
}
$content = html::image(array
(
'src' => 'media/images/icons/status/success.png',
'class' => 'status_icon'
)
).'<b>'.__('Imported').': '.$imported.'</b><br>';
$content .= html::image(array
(
'src' => 'media/images/icons/status/warning.png',
'class' => 'status_icon'
)
).'<b>'.__('Skipped').': '.$skipped.'</b><br>';
$content .= html::image(array
(
'src' => 'media/images/icons/status/error.png',
'class' => 'status_icon'
)
).'<b>'.__('Bad').': '.$bad.'</b><br>';
$headline = __('Import results');
// bread crumbs
$breadcrumbs = breadcrumbs::add()
->link('device_templates/show_all', 'Device templates',
$this->acl_check_view('Devices_Controller', 'devices'))
->link('device_templates/import_from_file', 'Upload device templates',
$this->acl_check_view('Devices_Controller', 'devices'))
->text('Import results')
->html();
}
else
{
//Error
$upload_form->file->add_error('requied', __('Error - can\'t read file'));
$content = $upload_form->html();
}
}
else
{
$content = $upload_form->html();
}
// view
$view = new View('main');
$view->title = $headline;
$view->content = new View('form');
$view->breadcrumbs = $breadcrumbs;
$view->content->headline = $headline;
$view->content->form = $content;
$view->render(TRUE);
}
/**
* Function returns all device templates in JSON format
*
* @author David Raška
*/
public function export_to_json()
{
// check acess
if (!$this->acl_check_view('Devices_Controller', 'devices'))
{
Controller::error(ACCESS);
}
// model
$device_templates = new Device_template_Model();
// gets data
$result = $device_templates->find_all();
$templates_array = array();
foreach ($result AS $template)
{
$templates_array[] = array
(
'enum_type_id' => $template->enum_type_id,
//'name' => $template->name,
'values' => json_decode($template->values),
'default' => $template->default
);
}
$data = json_encode($templates_array);
//JSON headers
Json_Controller::send_json_headers();
@header('Content-Disposition: attachment; filename="device_templates.json"');
@header('Content-Transfer-Encoding: binary');
@header('Content-Length: '. strlen($data));
@header('Pragma: no-cache');
echo $data;
}
/**
* Validate form value
*
* @param array $vals Reference to value
freenetis/branches/testing/application/controllers/json.php
*/
public static function send_json_headers()
{
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
@header('Cache-Control: no-cache, must-revalidate');
@header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@header('Content-type: application/json');
}
/**

Také k dispozici: Unified diff