summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7d7c944)
raw | patch | inline | side by side (parent: 7d7c944)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 20 May 2008 13:18:12 +0000 (13:18 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 20 May 2008 13:18:12 +0000 (13:18 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10967 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-plugins/goto/addons/goto/class_goto_import_file.inc | [new file with mode: 0644] | patch | blob |
gosa-plugins/goto/addons/goto/class_gotomasses.inc | patch | blob | history | |
gosa-plugins/goto/addons/goto/goto_import_file.tpl | [new file with mode: 0644] | patch | blob |
diff --git a/gosa-plugins/goto/addons/goto/class_goto_import_file.inc b/gosa-plugins/goto/addons/goto/class_goto_import_file.inc
--- /dev/null
@@ -0,0 +1,161 @@
+<?php
+
+class goto_import_file extends plugin
+{
+
+ var $events = array();
+ var $csv_fields = array();
+
+ public function __construct($config,&$parent)
+ {
+ plugin::plugin($config,NULL);
+ $this->parent = $parent;
+ $this->daemon_events = DaemonEvent::get_event_types( SYSTEM_EVENT);
+
+ $this->csv_fields = array(
+ "0" => "MAC", "1" => "HEADER", "2" => "OGROUP",
+ "3" => "BASE", "4" => "FQDN", "5" => "IP", "6" => "DHCP");
+ }
+
+
+ private function parse_csv($str)
+ {
+
+ /* Some file checks
+ */
+ $lines = split("\n",$str);
+ if(empty($str) || !count($lines)){
+ msg_dialog::display(_("Import"),_("Could not import file, it seems to be empty."),ERROR_DIALOG);
+ return;
+ }
+
+ /* Reset current events
+ */
+ $this->events = array();
+
+ /* Parse each line of the given file
+ */
+ foreach($lines as $line){
+
+ // Skip empty lines.
+ if(empty($line)) continue;
+
+ /* Load values from file
+ */
+ $fields = split(";",$line);
+ $event = array();
+ foreach($this->csv_fields as $key => $val) {
+ $event[$val] = "";
+ if(isset($fields[$key])){
+ $event[$val] = $fields[$key];
+ }
+ }
+ $this->events[] = $event;
+ }
+ $this->check_fields();
+ }
+
+
+ public function execute()
+ {
+ /* Import file
+ */
+ if(isset($_POST['import']) && isset($_FILES['file'])) {
+ if(isset($_FILES['file']['tmp_name'])){
+ $str = file_get_contents($_FILES['file']['tmp_name']);
+ $this->parse_csv($str);
+ }
+ }
+
+ /* Import started
+ */
+ $confirmed = FALSE;
+ foreach($_POST as $name => $value){
+ if(preg_match("/^MSG_OK/",$name)){
+ $confirmed = TRUE;
+ }
+ }
+ if(isset($_POST['start_import']) || $confirmed){
+ $error = FALSE;
+ if(!$confirmed){
+ foreach($this->events as $event){
+ if(!empty($event['ERROR'])){
+ $error = TRUE;
+ break;
+ }
+ }
+ if($error){
+ msg_dialog::display(_("Import"),
+ _("Entries marked as having errors will be skippen, do you still want to proceed?"),CONFIRM_DIALOG);
+ }
+ }
+ if(!$error){
+
+ $success = 0;
+ $fail = 0;
+
+ foreach($this->events as $key => $event){
+ if(!empty($event['ERROR'])){
+ $fail ++;
+ continue;
+ }
+ $class= $this->daemon_events['QUEUED'][$event['HEADER']];
+ $object = new $class($this->config);
+ $object->set_type(TRIGGERED_EVENT);
+ $object->add_targets(array($event['MAC']));
+ if(!$this->parent->o_queue->append($object)){
+ msg_dialog::display(_("Service infrastructure"),msgPool::siError($this->parent->o_queue->get_error()),ERROR_DIALOG);
+ $fail ++;
+ }else{
+ unset($this->events[$key]);
+ $success ++;
+ }
+ }
+ msg_dialog::display(_("Import"),sprintf(_("Import complete: %s events successfully send, %s failed."),$success,$fail),INFO_DIALOG);
+ }
+ }
+
+
+ /* Prepare output
+ */
+ $evts = $this->events;
+ foreach($this->events as $id => $evt){
+ foreach($evt as $key => $val){
+ if(in_array($key,$this->csv_fields)){
+ $evts[$id][$key] = "<span style=\"white-space: nowrap;\">".strip_tags($val)."</span>";
+ }
+ }
+ }
+
+ $smarty = get_smarty();
+ $smarty->assign("info",$evts);
+ $smarty->assign("count",count($evts));
+ return($smarty->fetch(get_template_path('goto_import_file.tpl', TRUE)));
+ }
+
+
+ public function check()
+ {
+ $message = plugin::check();
+ $this->check_fields();
+ return($message);
+ }
+
+
+ private function check_fields()
+ {
+ foreach($this->events as $key => $event){
+ $this->events[$key]['ERROR'] = "";
+ if(empty($event['MAC']) || !tests::is_mac($event['MAC'])){
+ $this->events[$key]['ERROR'] .= msgPool::invalid(_("Mac")).", ";
+ }
+ if(empty($event['HEADER']) || !isset($this->daemon_events['QUEUED'][$event['HEADER']])){
+ $this->events[$key]['ERROR'] .= msgPool::invalid(_("Event")).", ";
+ }
+ $this->events[$key]['ERROR'] = trim($this->events[$key]['ERROR'],", ");
+ }
+ }
+}
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/gosa-plugins/goto/addons/goto/class_gotomasses.inc b/gosa-plugins/goto/addons/goto/class_gotomasses.inc
index 31652669931c59a6ee24460dd0d9f3b5fd42bcf9..00d46d86abaeed824aa5cb9c15b3dcbd8d393640 100644 (file)
}
+ /************
+ * Import CSV file
+ ************/
+
+ if($s_action == "import_file"){
+ $this->dialog = new goto_import_file($this->config,$this);
+ }
+
+ if(isset($_POST['import_abort'])){
+ $this->dialog = FALSE;
+ }
+
+
/************
* Handle Priority modifications
************/
}
if($this->acl_is_removeable()){
$s.= "..|---|\n";
+ $s.= "..|<img src='images/alternatemail.png' alt='' border='0' class='center'> "._("Import")."|import_file\n";
$s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'> "._("Remove")."|remove_multiple\n";
}
if(preg_match("/w/",$this->getacl(""))){
diff --git a/gosa-plugins/goto/addons/goto/goto_import_file.tpl b/gosa-plugins/goto/addons/goto/goto_import_file.tpl
--- /dev/null
@@ -0,0 +1,77 @@
+<h2>{t}Import jobs{/t}</h2>
+
+<table>
+ <tr>
+ <td>
+ {t}Select the file to import{/t}
+ </td>
+ <td>
+ <input type='file' name='file' value="{t}Browse{/t}">
+ <input type='submit' name='import' value='{t}Load{/t}'>
+ </td>
+ </tr>
+ {if $count}
+ <tr>
+ <td>{t}Start import{/t}</td>
+ <td>
+ <input type='submit' name='start_import' value='{t}Import{/t}'>
+ </td>
+ </tr>
+ {/if}
+</table>
+
+ {if $count}
+ <p class="seperator"> </p>
+ <br>
+ <br>
+ <div style='width:100%; height:300px; overflow: scroll;'>
+ <table cellpadding="3" cellspacing="0" style='width:100%; background-color: #CCCCCC; border: solid 1px #CCCCCC;'>
+ <tr>
+ <td><b>{t}Mac{/t}</b></td>
+ <td><b>{t}Event{/t}</b></td>
+ <td><b>{t}Object group{/t}</b></td>
+ <td><b>{t}Base{/t}</b></td>
+ <td><b>{t}FQDN{/t}</b></td>
+ <td><b>{t}IP{/t}</b></td>
+ <td><b>{t}DHCP{/t}</b></td>
+ </tr>
+ {foreach from=$info item=item key=key}
+ {if $item.ERROR}
+ <tr style='background-color: #F0BBBB;'>
+ <td>{$item.MAC}</td>
+ <td>{$item.HEADER}</td>
+ <td>{$item.OGROUP}</td>
+ <td>{$item.BASE}</td>
+ <td>{$item.FQDN}</td>
+ <td>{$item.IP}</td>
+ <td>{$item.DHCP}</td>
+ </tr>
+ <tr style='background-color: #F0BBBB;'>
+ <td colspan="7"><b>{$item.ERROR}</b></td>
+ </tr>
+ {else}
+ {if ($key % 2)}
+ <tr class="rowxp0">
+ {else}
+ <tr class="rowxp1">
+ {/if}
+
+ <td>{$item.MAC}</td>
+ <td style='border-left: solid 1px #BBBBBB;'>{$item.HEADER}</td>
+ <td style='border-left: solid 1px #BBBBBB;'>{$item.OGROUP}</td>
+ <td style='border-left: solid 1px #BBBBBB;'>{$item.BASE}</td>
+ <td style='border-left: solid 1px #BBBBBB;'>{$item.FQDN}</td>
+ <td style='border-left: solid 1px #BBBBBB;'>{$item.IP}</td>
+ <td style='border-left: solid 1px #BBBBBB;'>{$item.DHCP}</td>
+ </tr>
+ {/if}
+ {/foreach}
+ </table>
+ </div>
+ {/if}
+<br>
+<p class='seperator'></p>
+<div style='text-align:right;width:99%; padding-right:5px; padding-top:5px;'>
+ <input type='submit' name='import_abort' value='{msgPool type=okButton}'>
+</div>
+<br>