00001
00002
00003
00004
00005
00006 #include <string>
00007
00008 #include "openLogger.h"
00009 using namespace std;
00010
00011
00012 #include "w3intranet.h"
00013 #include "page_enhancements.hpp"
00014 #include "Document.hpp"
00015
00016 class document_list_functor: public base_functor
00017 {
00018 cgiScript & script;
00019 bool CanEdit;
00020 bool IsSignedIn;
00021 bool Secured;
00022 Document_Obj document;
00023 public:
00024 document_list_functor(page & ipg,cgiScript & script, bool CanEdit, bool IsSignedIn)
00025 :base_functor(ipg),script(script),CanEdit(CanEdit),IsSignedIn(IsSignedIn),Secured(false)
00026 {;}
00027 virtual ~document_list_functor()
00028 {;}
00029
00030 virtual bool operator()( xmlNode & node )
00031 {
00032 bool bRet = false;
00033
00034 node_attr::iterator x = node.attr.find("secured");
00035 if( x!=node.attr.end() && x->second == "true") Secured = true;
00036
00037 paragraphMap & paras = pg.get_template().getParagraphs();
00038 ocString category, entries;
00039
00040 if( IsSignedIn == true || Secured == false )
00041 {
00042 x = node.attr.find("category");
00043 if( x!=node.attr.end() )
00044 {
00045 category = paras[x->second];
00046 }
00047 else
00048 {
00049
00050 script << "can't find document_list 'category' tag " << endl;
00051 }
00052 x = node.attr.find("entries");
00053 if( x!=node.attr.end() )
00054 {
00055 entries = paras[x->second];
00056
00057
00058 string clause = "Visible > 0";
00059
00060 if( document.get_data(clause, "Sequence, Category, Name" ) )
00061 {
00062 string lastCat;
00063 do {
00064 if ( lastCat != document.Category )
00065 {
00066 lastCat = document.Category;
00067 script << category.replace("$category$",lastCat);
00068 }
00069 ocString documentId;
00070 documentId.append(document.Id);
00071 editIcon( paras, node, documentId );
00072 script << entries
00073 .replaceAll("$id$", documentId)
00074 .replace("$location$",document.Filename)
00075 .replaceAll("$label$",document.Name)
00076 .replace("$description$",document.Description);
00077
00078 } while(document.next());
00079 }
00080 else
00081 {
00082 script << document.last_result();
00083 }
00084 }
00085 else
00086 {
00087 script << "can't find document_list 'entries' tag " << endl;
00088 }
00089 addIcon( paras, node );
00090 }
00091
00092 return bRet;
00093 }
00094
00095 void editIcon( paragraphMap & paras, xmlNode & node, string Id )
00096 {
00097 if( CanEdit )
00098 {
00099 ocString editLink;
00100 node_attr::iterator x = node.attr.find("editlink");
00101 if( x!=node.attr.end() )
00102 {
00103 editLink = paras[x->second];
00104 script << editLink
00105 .replaceAll("$id$", Id );
00106 }
00107 else
00108 {
00109 script << "can't find document_list 'editLink' tag " << endl;
00110 }
00111 }
00112 }
00113 void addIcon( paragraphMap & paras, xmlNode & node )
00114 {
00115 if( CanEdit )
00116 {
00117 ocString addLink;
00118 node_attr::iterator x = node.attr.find("addlink");
00119 if( x!=node.attr.end() )
00120 {
00121 addLink = paras[x->second];
00122 script << addLink;
00123 }
00124 else
00125 {
00126 script << "can't find document_list 'addlink' tag " << endl;
00127 }
00128 }
00129 }
00130
00131 };
00132
00133 bool intraMain(page & pg ,cgiScript & script)
00134 {
00135 return true;
00136 }
00137
00138
00139 int main(int argc, char ** argv)
00140 {
00141 baseUrl = "intranet.meta";
00142
00143 cgiScript script("text/html",false);
00144 isSignedOn = check(script);
00145 script.closeHeader();
00146
00147 page pg(script);
00148
00149 writelog( "load page" );
00150 if( pg.load() )
00151 {
00152 writelog( "instance of page control" );
00153 page_control ctrl(pg);
00154 ctrl.addOp ( "servicelist", new servicelist_functor(pg,script,isSignedOn) );
00155 ctrl.addOp ( "userinterface", new form_functor(pg,script,isSignedOn) );
00156 ctrl.addOp ( "qrycontent", new qrystr_content_functor(pg,script) );
00157 ctrl.addOp ( "documentlist", new document_list_functor(pg,script,oLogin.SiteAdmin(), isSignedOn) );
00158 writelog( "page control emit" );
00159 ctrl.emit();
00160 }
00161 else
00162 {
00163 script << "<html><head><title>Page Unavailable</title></head>" << endl
00164 << "<body><h1>Sorry</h1>" << endl
00165 << "<p>The page you requested is not available</p></body></html>";
00166 }
00167 return 0;
00168 }
00169
00170
00171 #include "read_write_base.cpp"