Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members
readprofiles.cpp
00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: Readprofiles.cpp * 00006 * * 00007 * * 00008 * * 00009 * ITEC institute of the University of Klagenfurt (Austria) * 00010 * http://www.itec.uni-klu.ac.at * 00011 * * 00012 * * 00013 * For more information visit the ViTooKi homepage: * 00014 * http://ViTooKi.sourceforge.net * 00015 * vitooki-user@lists.sourceforge.net * 00016 * vitooki-devel@lists.sourceforge.net * 00017 * * 00018 * This file is part of ViTooKi, a free video toolkit. * 00019 * ViTooKi is free software; you can redistribute it and/or * 00020 * modify it under the terms of the GNU General Public License * 00021 * as published by the Free Software Foundation; either version 2 * 00022 * of the License, or (at your option) any later version. * 00023 * * 00024 * This program is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU General Public License * 00030 * along with this program; if not, write to the Free Software * 00031 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 00032 * MA 02111-1307, USA. * 00033 * * 00034 ***********************************************************************/ 00035 00036 /*********************************************************************** 00037 * * 00038 * REVISION HISTORY: * 00039 * * 00040 * * 00041 * * 00042 ***********************************************************************/ 00043 00044 /*********************************************************************** 00045 * Video Session Migration System, 2004 * 00046 * Author: Klaus Schoeffmann * 00047 ************************************************************************/ 00048 00049 00050 #include "readprofiles.hpp" 00051 00052 /***********************************************************************/ 00053 void createProfileSelection(UserList *ul, uint userId) 00054 { 00055 cout << "<select tabindex=\"1\" size=\"3\" style=\"width:80%\" id=\"proid\" name=\"proid\" class=\"darkblueborder\" onChange=\"showProfileInfo(this.value);\">"; 00056 //output all profiles for chosen user 00057 User* user = ul->getUserById(userId); 00058 vector<Profile*> profiles = user->getProfiles(); 00059 vector<Profile*>::const_iterator piter = profiles.begin(); 00060 for (;piter != profiles.end(); piter++) 00061 { 00062 Profile *profile = *piter; 00063 cout << "<option value=\"" << profile->getProfileId() << "\">"; 00064 cout << profile->getProfileName(); 00065 cout << "</option>" << endl; 00066 } 00067 cout << "</select>"; 00068 } 00069 00070 /***********************************************************************/ 00071 void createJavaScriptCode(UserList *ul, uint userId) 00072 { 00073 cout << "<script language=\"javascript\">" << endl; 00074 00075 //first create arrays containing profile information 00076 User* user = ul->getUserById(userId); 00077 vector<Profile*> profiles = user->getProfiles(); 00078 if (profiles.size() > 0) 00079 { 00080 ostringstream str; 00081 cout << "profileInfo = new Array(" << profiles.size() << ");" << endl; 00082 vector<Profile*>::const_iterator piter = profiles.begin(); 00083 for (uint i=0;piter != profiles.end(); piter++, i++) 00084 { 00085 Profile *profile = *piter; 00086 00087 if (piter != profiles.begin()) str << ", "; 00088 00089 cout << "profileInfo[" << i << "] = "; 00090 cout << "\"Width=" << profile->getWidth(); 00091 cout << " Height=" << profile->getHeight(); 00092 cout << " Color=" << (profile->isColorCapable() == true ? "yes" : "no"); 00093 cout << " Bpp=" << profile->getBitsPerPixel(); 00094 cout << " Bufferms=" << profile->getBufferingDelayms(); 00095 cout << " NetkBps=" << profile->getNetkBps(); 00096 cout << " refreshRate=" << profile->getRefreshRate() << "\";" << endl; 00097 } 00098 } 00099 00100 cout << "document.getElementById('proid').focus();" << endl; 00101 00102 cout << "function disableLogon() {" << endl; 00103 cout << " document.getElementById('password').disabled = true;" << endl; 00104 cout << " document.getElementById('submit').disabled = true;" << endl; 00105 cout << "}" << endl; 00106 00107 cout << "function showProfileInfo(nr) {" << endl; 00108 cout << " document.getElementById('info').value = profileInfo[nr-1];" << endl; 00109 cout << " document.getElementById('password').focus();" << endl; 00110 cout << "}" << endl; 00111 00112 cout << "function disableInputs() {" << endl; 00113 cout << " document.getElementById('proid').disabled = true;" << endl; 00114 cout << " disableLogon();" << endl; 00115 cout << "}" << endl; 00116 00117 //if no profiles found, disable password-field and logon-button 00118 if (profiles.size() == 0) 00119 { 00120 cout << "disableLogon();" << endl; 00121 } 00122 cout << "</script>" << endl; 00123 } 00124 00125 /***********************************************************************/ 00126 int main (void) 00127 { 00128 00129 //read all users 00130 UserList *ul = new UserList(); 00131 ul->readUsersFromFile(Globals::getConfigFilePath()); 00132 00133 //read all profiles 00134 //(and add each profile to corresponding user) 00135 ProfileList *profl = new ProfileList(); 00136 profl->readProfilesFromFile(Globals::getConfigFilePath(), ul); 00137 00138 //read form data (userid) 00139 string formdata; 00140 cin >> formdata; 00141 CGIParser cgiparser (formdata); 00142 uint userId = atoi(cgiparser.getFieldValue("userid").c_str()); 00143 uint pageSize = atoi(cgiparser.getFieldValue("pagesize").c_str()); 00144 if (pageSize == 0) pageSize = 1; 00145 00146 00147 cout << html::getHTMLHeader(); 00148 cout << html::getMenu("readprofiles.cgi", pageSize); 00149 html::createPageSizeForm(cgiparser.createOpenForm("frmPageSize", "readprofiles.cgi", "post", ""), pageSize); 00150 00151 //userId must be specified! 00152 if (userId == 0) 00153 { 00154 cout << html::error("You must first select an user!") << endl; 00155 exit(1); 00156 } 00157 00158 //create form and selection-box for profiles 00159 cout << "<form action=\"" << Globals::getCGIPath() << "logon.cgi\" method=\"post\">"; 00160 cout << "<input type=\"hidden\" id=\"userid\" name=\"userid\" value=\"" << userId << "\">"; 00161 cout << "<input type=\"hidden\" id=\"linktype\" name=\"linktype\" value=\"" << LINK_RTSP << "\">"; 00162 cout << "<input type=\"hidden\" id=\"subtractSecs\" name=\"subtractSecs\" value=\"2\">"; 00163 cout << "<input type=\"hidden\" id=\"pagesize\" name=\"pagesize\" value=\"" << pageSize << "\">"; 00164 cout << "<input type=\"hidden\" id=\"showAS\" name=\"showAS\" value=\"on\">"; 00165 cout << "<input type=\"hidden\" id=\"showMS\" name=\"showMS\" value=\"on\">"; 00166 if (cgiparser.getFieldValue("proxysupported") == "on") { 00167 cout << "<input type=\"hidden\" id=\"proxysupported\" name=\"proxysupported\" value=\"on\">"; 00168 } else { 00169 cout << "<input type=\"hidden\" id=\"sphost\" name=\"sphost\" value=\"" << cgiparser.getFieldValue("sphost") << "\">"; 00170 cout << "<input type=\"hidden\" id=\"spport\" name=\"spport\" value=\"" << cgiparser.getFieldValue("spport") << "\">"; 00171 } 00172 cout << "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"; 00173 cout << "<tr><td colspan=\"2\" align=\"left\">Hello <b>" << ul->getUserById(userId)->getUsername() << "</b><br><br></td></tr>" << endl; 00174 cout << "<tr><td colspan=\"2\" align=\"left\">Please choose a profile:</td></tr>" << endl; 00175 00176 //create selectbox for profiles 00177 cout << "<tr><td colspan=\"2\" align=\"left\">" << endl; 00178 createProfileSelection(ul, userId); 00179 cout << "</td></tr>"; 00180 00181 //create input field for password 00182 cout << "<tr><td colspan=\"2\" align=\"left\">Input password:</td></tr>" << endl; 00183 cout << "<tr><td align=\"left\" width=\"50%\"><input tabindex=\"2\" " 00184 << "type=\"password\" id=\"password\" name=\"password\" class=\"darkblueborder\" " 00185 << "size=\"12\" style=\"width:80%\" maxlength=\"30\"></td>" << endl; 00186 cout << "<td align=\"left\" width=\"50%\"><input tabindex=\"5\" " 00187 << "type=\"submit\" id=\"submit\" name=\"submit\" value=\"Logon\">" << endl; 00188 cout << "</td></tr>" << endl; 00189 00190 //create hidden layer used to display profile info 00191 //cout << "<br><div id=\"info\" class=\"profileinfo\"><br><br></div>" << endl; 00192 cout << "<tr><td colspan=\"2\"><br>Profile info:<br>" 00193 << "<textarea cols=20 rows=4 id=\"info\" class=\"profileinfo\"></textarea></td></tr>" << endl; 00194 00195 cout << "</table></form>"; 00196 00197 //create scripting part, used to display profile info and for input-protection 00198 createJavaScriptCode(ul, userId); 00199 00200 cout << html::getHTMLFooter(cgiparser.createRefreshForm("readprofiles.cgi", "post")); 00201 00202 delete ul; 00203 delete profl; 00204 00205 return 0; 00206 }