/[drupal]/contributions/modules/pacs/pacs_xml.inc
ViewVC logotype

Diff of /contributions/modules/pacs/pacs_xml.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1, Sat Jun 24 15:35:37 2006 UTC revision 1.2, Mon Jun 26 23:54:29 2006 UTC
# Line 18  function pacs_xml_save_node() { Line 18  function pacs_xml_save_node() {
18    global $user, $_PACS_XML_NODE, $_PACS_XML_NIDS;    global $user, $_PACS_XML_NODE, $_PACS_XML_NIDS;
19    
20    $_PACS_XML_NODE->uid = $user->uid;    $_PACS_XML_NODE->uid = $user->uid;
21    $_PACS_XML_NIDS[$_PACS_XML_NODE->nid] = 0;    $_PACS_XML_NODE->format = 1;
22    unset($_PACS_XML_NODE->nid);  // it will be a new node, with a new nid    node_save($_PACS_XML_NODE);
23      //pacs_debug('saved_node='.print_r($_PACS_XML_NODE,1),1);
24    pacs_debug('pacs_node='.print_r($_PACS_XML_NODE,1),1);  
25      $_PACS_XML_NIDS[$_PACS_XML_NODE->pacs_nid] = $_PACS_XML_NODE->nid;
26    //node_save($_PACS_XML_NODE);    if ($_PACS_XML_NODE->pacs_index == 0) $_PACS_XML_NIDS[0] = $_PACS_XML_NODE->nid;
27      $pid = $_PACS_XML_NIDS[$_PACS_XML_NODE->pacs_pid];
28      if (!$pid) $pid = 0;
29      $pnode = array('nid' => $_PACS_XML_NODE->nid, 'pid' => $pid, 'rid' => 0, 'stops' => array());
30      pacs_update_node($pnode);
31      if ($_PACS_XML_NODE->type == 'book') {
32        // if the node is a book page, update the book hierarchy
33        db_query("REPLACE {book} SET vid = %d, nid = %d, parent = %d",
34          $_PACS_XML_NODE->vid, $_PACS_XML_NODE->nid, $pid);
35      }
36  }  }
37    
38  function pacs_xml_start_element($parser,$name,$attrs) {  function pacs_xml_start_element($parser,$name,$attrs) {
# Line 31  function pacs_xml_start_element($parser, Line 40  function pacs_xml_start_element($parser,
40    
41    switch ($name) {    switch ($name) {
42      case 'NODE':      case 'NODE':
43        unset($_PACS_XML_NODE);        $_PACS_XML_NODE = (object) NULL;
44        $_PACS_XML_NODE = stdClass;        $_PACS_XML_NODE->pacs_nid = $attrs['NID'];
       $_PACS_XML_NODE->nid = $attrs['NID'];  
45        break;        break;
46      case 'DRUPAL_VERSION':      case 'DRUPAL_VERSION':
47      case 'TYPE':      case 'TYPE':
# Line 56  function pacs_xml_element_content($parse Line 64  function pacs_xml_element_content($parse
64    global $_PACS_XML_TAG, $_PACS_XML_NODE;    global $_PACS_XML_TAG, $_PACS_XML_NODE;
65    
66    switch ($_PACS_XML_TAG) {    switch ($_PACS_XML_TAG) {
67        /*
68      case 'DRUPAL_VERSION':      case 'DRUPAL_VERSION':
69        if ($data != '4.7') {        if ($data != '4.7') {
70          drupal_set_message(t('Incompatible Drupal version.'),'error');          drupal_set_message(t('Incompatible Drupal version.'),'error');
71          drupal_goto("node/$nid/tree");          drupal_goto("node/$nid/tree");
72        }        }
73        break;        break;
74        */
75      case 'TYPE':      case 'TYPE':
76        $_PACS_XML_NODE->type = $data;        $_PACS_XML_NODE->type = $data;
77        break;        break;
# Line 78  function pacs_xml_element_content($parse Line 88  function pacs_xml_element_content($parse
88        $_PACS_XML_NODE->sticky = $data;        $_PACS_XML_NODE->sticky = $data;
89        break;        break;
90      case 'TITLE':      case 'TITLE':
91        $_PACS_XML_NODE->title = $data;        $_PACS_XML_NODE->title .= $data;
92        break;        break;
93      case 'TEASER':      case 'TEASER':
94        $_PACS_XML_NODE->teaser = $data;        $_PACS_XML_NODE->teaser .= $data;
95        break;        break;
96      case 'BODY':      case 'BODY':
97        $_PACS_XML_NODE->body = $data;        $_PACS_XML_NODE->body .= $data;
98        break;        break;
99      case 'LOG':      case 'LOG':
100        $_PACS_XML_NODE->log = $data;        $_PACS_XML_NODE->log .= $data;
101        break;        break;
102      case 'PACS_INDEX':      case 'PACS_INDEX':
103        $_PACS_XML_NODE->index = $data;        $_PACS_XML_NODE->pacs_index = $data;
104        break;        break;
105      case 'PACS_PID':      case 'PACS_PID':
106        $_PACS_XML_NODE->pid = $data;        $_PACS_XML_NODE->pacs_pid = $data;
107        break;        break;
108    }    }
109  }  }
110    
111  function pacs_xml_end_element($parser,$name) {  function pacs_xml_end_element($parser,$name) {
112    global $_PACS_XML_TAG;    global $_PACS_XML_TAG, $_PACS_XML_NODE;
113    
114    if ($_PACS_XML_TAG == $name) $_PACS_XML_TAG = '';    if ($_PACS_XML_TAG == $name) $_PACS_XML_TAG = '';
115    if ($name == 'NODE') pacs_xml_save_node();    if ($name == 'NODE') pacs_xml_save_node();
116  }  }
117    
118  function pacs_xml_parse($nid) {  function pacs_xml_parse($nid) {
119      global $_PACS_XML_NIDS;
120    
121    $file = $_FILES['branch_file']['tmp_name'];    $file = $_FILES['branch_file']['tmp_name'];
122    if (!$file) {    if (!$file || !is_uploaded_file($file)) {
123      drupal_set_message(t('Branch file upload failed.'),'error');      drupal_set_message(t('Branch file upload failed.'),'error');
124      drupal_goto("node/$nid/tree");      drupal_goto("node/$nid/tree");
125    }    }
126    $xml = xml_parser_create();    $xml = xml_parser_create();
127      xml_parser_set_option ($xml,XML_OPTION_SKIP_WHITE,1);
128    xml_set_element_handler($xml,'pacs_xml_start_element','pacs_xml_end_element');    xml_set_element_handler($xml,'pacs_xml_start_element','pacs_xml_end_element');
129    xml_set_character_data_handler($xml,'pacs_xml_element_content');    xml_set_character_data_handler($xml,'pacs_xml_element_content');
130    $fp = fopen($file,"r");    $fp = fopen($file,"r");
# Line 129  function pacs_xml_parse($nid) { Line 142  function pacs_xml_parse($nid) {
142      }      }
143    }    }
144    xml_parser_free($xml);    xml_parser_free($xml);
145      pacs_move_node($_PACS_XML_NIDS[0],$nid,FALSE);
146    drupal_goto("node/$nid/tree");    drupal_goto("node/$nid/tree");
147  }  }
148    
149  function pacs_xml_import($nid) {  function pacs_xml_import($nid) {
150    $output = '';    $output = '';
151    
152      if ($_POST['op_cancel']) drupal_goto("node/$nid/tree");
153    if (isset($_FILES['branch_file'])) pacs_xml_parse($nid);    if (isset($_FILES['branch_file'])) pacs_xml_parse($nid);
154    
155    $output .= '<fieldset class="xml_import"><legend>'.t('Pacs Branch Import').'</legend>';    // file upload form
156    $output .= '<form enctype="multipart/form-data" method="POST">';    $form['#attributes'] = array('enctype'=>'multipart/form-data');
157    $output .= '<div><input name="branch_file" type="file" /></div>';    $form['import'] = array('#type'=>'fieldset','#title'=>t('Pacs Branch Import'),
158    $output .= '<div><input type="submit" value="'.t('upload').'" /></div>';      '#description'=>t('Select a valid pacs export file to upload:'));
159    $output .= '</form>';    $form['import']['file'] = array('#type'=>'file','#name'=>'branch_file','#size'=>'45',);
160    $output .= '</fieldset>';    $form['import']['cancel'] = array('#prefix'=>'<div>','#type'=>'submit',
161        '#name'=>'op_cancel','#value'=>t('cancel'),);
162      $form['import']['upload'] = array('#type'=>'submit','#value'=>t('upload'),'#suffix'=>'</div>',);
163      $output .= drupal_get_form('xml_import',$form);
164    print theme('page',$output);    print theme('page',$output);
165  }  }
166    
# Line 156  function pacs_xml_export_node($nid) { Line 173  function pacs_xml_export_node($nid) {
173    
174    if ($node = node_load($nid,NULL,TRUE)) {    if ($node = node_load($nid,NULL,TRUE)) {
175      print "<node nid=\"$nid\">\n";      print "<node nid=\"$nid\">\n";
   
     // the core fields  
176      print "<type>".$node->type."</type>\n";      print "<type>".$node->type."</type>\n";
177      print "<status>".$node->status."</status>\n";      print "<status>".$node->status."</status>\n";
178      print "<promote>".$node->promote."</promote>\n";      print "<promote>".$node->promote."</promote>\n";
# Line 167  function pacs_xml_export_node($nid) { Line 182  function pacs_xml_export_node($nid) {
182      print "<teaser><![CDATA[".$node->teaser."]]></teaser>\n";      print "<teaser><![CDATA[".$node->teaser."]]></teaser>\n";
183      print "<body><![CDATA[".$node->body."]]></body>\n";      print "<body><![CDATA[".$node->body."]]></body>\n";
184      print "<log><![CDATA[".$node->log."]]></log>\n";      print "<log><![CDATA[".$node->log."]]></log>\n";
     // the pacs fields  
185      print "<pacs_index>$node_index</pacs_index>\n";  $node_index++;      print "<pacs_index>$node_index</pacs_index>\n";  $node_index++;
186      print "<pacs_pid>".$node->pacs['pid']."</pacs_pid>\n";      print "<pacs_pid>".$node->pacs['pid']."</pacs_pid>\n";
   
187      print "</node>\n";      print "</node>\n";
188    }    }
189  }  }
190    
191  function pacs_xml_export_branch($nid) {  function pacs_xml_export_branch($nid) {
192    pacs_xml_export_node($nid);    pacs_xml_export_node($nid);
193    if ($list = pacs_child_list($nid)) {    if ($list = pacs_child_list($nid)) foreach ($list as $chd) pacs_xml_export_branch($chd);
     foreach ($list as $nid) pacs_xml_export_branch($nid);  
   }  
194  }  }
195    
196  function pacs_xml_export($nid) {  function pacs_xml_export($nid) {
197      $xml_file_name = 'drupal_branch_'.$nid.'.xml';
   $xml_file_name = 'drupal_branch.xml';  
198    drupal_set_header('Content-Type: application/octet-stream');    drupal_set_header('Content-Type: application/octet-stream');
199    drupal_set_header('Content-Disposition: attachment; filename='.$xml_file_name);    drupal_set_header('Content-Disposition: attachment; filename='.$xml_file_name);
200    
201    print '<?xml version="1.0" encoding="UTF-8" ?>'."\n";    print '<?xml version="1.0" encoding="UTF-8"?>'."\n";
202    print "<pacs_branch>\n";    print "<pacs_branch>\n";
203    print "<drupal_version>4.7</drupal_version>\n";    print "<drupal_version>4.7</drupal_version>\n";
   
204    pacs_xml_export_branch($nid);    pacs_xml_export_branch($nid);
   
205    print "</pacs_branch>\n";    print "</pacs_branch>\n";
206    
207    exit;    exit;
208  }  }
209    
210    
211    // delete branch ////////////////////////////////////////////////
212    
213    
214    function pacs_del_branch($nid) {
215      node_delete($nid);
216      if ($list = pacs_child_list($nid)) foreach ($list as $chd) pacs_del_branch($chd);
217    }
218    
219    function pacs_delete_branch($nid) {
220      $pnode = pacs_node($nid);
221      if ($_POST['op_delete']) {
222        pacs_del_branch($nid);
223        drupal_goto('node/'.$pnode['pid'].'/tree');
224      } elseif ($_POST['op_cancel']) {
225        drupal_goto('node/'.$nid.'/tree');
226      }
227      drupal_set_message(
228        t('Do you want to delete the branch under the node <strong>%title</strong> (inclusive) ?',
229        array('%title'=>$pnode['title'])),'error'
230      );
231      $output = '';
232      $form['cancel'] = array('#type'=>'submit','#name'=>'op_cancel','#value'=>t('cancel'));
233      $form['delete'] = array('#type'=>'submit','#name'=>'op_delete','#value'=>t('delete branch'));
234      $output .= drupal_get_form('delete_confirmation',$form);
235      print theme('page',$output);
236    }
237    
238  ?>  ?>

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.2