pages/item_ajax.inc.php

00001 <?php if(!function_exists('startedIndexPhp')) { header("location:../index.php"); exit();}
00002 require_once("db/class_task.inc.php");
00003 require_once("db/class_project.inc.php");
00004 
00015 function itemLoadField()
00016 {
00017     header("Content-type: text/html; charset=utf-8");
00018     if(!$item_id=get('item')) {
00019         return NULL;
00020     }
00021     if(!$item= DbProjectItem::getVisibleById($item_id)) {
00022         return NULL;
00023     }
00024     if(!$object= DbProjectItem::getObjectById($item_id)) {
00025         return NULL;
00026     }
00027 
00028     $field_name= 'description';
00029     if(get('field')) {
00030         $field_name= get('field');
00031     }
00032 
00033     
00034     if(!isset($object->fields[$field_name])) {
00035         return NULL;
00036     }
00037     require_once(confGet('DIR_STREBER') . 'render/render_wiki.inc.php');
00038     
00039     $chapter= get('chapter');
00040     if(is_null($chapter)) {
00041         print $object->$field_name;        
00042     }
00043     else {        
00044         print getOneWikiChapter($object->$field_name, $chapter);
00045     }
00046 }
00047 
00054 function itemSaveField()
00055 {
00056     header("Content-type: text/html; charset=utf-8");
00057     $value= get('value');
00058     if(is_null($value)) {
00059         return;
00060     }
00061 
00062     if(!$item_id=get('item')) {
00063         print "Failure";
00064         return;
00065     }
00066     global $g_wiki_project;
00067 
00068     if(!$item= DbProjectItem::getEditableById($item_id)) {
00069         print "Failure";
00070         return;
00071     }
00072     if(!$object= DbProjectItem::getObjectById($item_id)) {
00073         print "Failure";
00074         return;
00075     }
00076 
00077     $field_name= 'description';
00078     if(get('field')) {
00079         $field_name= get('field');
00080     }
00081     if(!isset($object->fields[$field_name])) {
00082         return NULL;
00083     }
00084     require_once(confGet('DIR_STREBER') . 'render/render_wiki.inc.php');
00085 
00086     $chapter= get('chapter');
00087     
00088     ### only replace chapter ###
00089     if(! is_null($chapter)) {
00090 
00091         require_once(confGet('DIR_STREBER') . 'render/render_wiki.inc.php');
00092         
00098         $org= $object->$field_name;
00099         $org= str_replace("\\", "\\\\", $org);
00100 
00101         $parts= getWikiChapters($org);
00102                 
00103         ### replace last line return (added by textarea) ###
00104         if(!preg_match("/\n$/",$value)) {
00105             $value.="\n";
00106         }
00107         $value= str_replace("\\'", "'", $value);
00108         $value= str_replace('\\"', "\"", $value);
00109         
00110         $parts[$chapter]= $value;
00111 
00112         $new_wiki_text= implode('', $parts);
00113         
00114         $object->$field_name = $new_wiki_text;
00115         $object->update(array($field_name));
00116 
00117         $new_wiki_text =stripslashes($new_wiki_text);
00118 
00119         $result= wiki2purehtml($new_wiki_text);
00120         print $result;
00121     }
00122     ### replace complete field ###
00123     else {
00124 
00125         $object->$field_name = $value;
00126         $object->update(array($field_name));
00127 
00128         print wiki2purehtml($object->$field_name); 
00129     }    
00130 }
00131 ?>

Generated on Sun Mar 4 17:19:31 2007 for streber by  doxygen 1.5.1-p1