00001 <?php if(!function_exists('startedIndexPhp')) { header("location:../index.php"); exit();}
00002 # streber - a php5 based project management system (c) 2005-2007 / www.streber-pm.org
00003 # Distributed under the terms and conditions of the GPL as stated in lang/license.html
00004
00012 require_once(confGet('DIR_STREBER') . 'db/class_task.inc.php');
00013 require_once(confGet('DIR_STREBER') . 'db/class_project.inc.php');
00014 require_once(confGet('DIR_STREBER') . 'db/class_person.inc.php');
00015 require_once(confGet('DIR_STREBER') . 'render/render_list.inc.php');
00016
00017
00018 global $g_tabs_login;
00019 $g_tabs_login= array(
00020 "login" =>array(
00021 'target'=>"index.php?go=loginForm",
00022 'title'=>__('Login','tab in top navigation'),
00023 'bg'=>"misc" ,
00024 'tooltip'=>__('Go to your home. Alt-h / Option-h'),
00025 ),
00026 "license" =>array(
00027 'target'=>"index.php?go=helpLicense",
00028 'title'=>__('License','tab in top navigation'),
00029 'tooltip'=>__('Your projects. Alt-P / Option-P'),
00030 'bg'=>"projects",
00031 'accesskey'=>'p'
00032 )
00033 );
00034
00035
00041 global $g_valid_login_params;
00042 $g_valid_login_params= array('prj','task','tsk','comment','effort','person','client');
00043
00049 function loginForm() {
00050 global $PH;
00051 global $auth;
00052 global $g_valid_login_params;
00053
00054 if(isset($auth->cur_user)) {
00055 $auth->cur_user=NULL;
00056 }
00057
00063 ### warn if install-dir present ###
00064 if(file_exists('install')) {
00065 new FeedbackWarning("<b>Install-directory still present.</b> This is a massive security issue (<a href='".confGet('STREBER_WIKI_URL')."installation'>read more</a>)"
00066 .'<ul><li><a href="install/remove_install_dir.php">remove install directory now.</a></ul>');
00067 }
00068
00069
00070 ### set up page and write header ###
00071 {
00072 $page= new Page(array('autofocus_field'=>'login_name'));
00073 global $g_tabs_login;
00074 $page->tabs= $g_tabs_login;
00075
00076 $page->cur_tab='login';
00077 $page->type="";
00078 $page->title=__('Welcome to streber','Page title');
00079 #$page->title_minor=__('please login');
00080
00081 echo(new PageHeader);
00082 }
00083 echo (new PageContentOpen);
00084
00085 ### write form ###
00086 {
00087 require_once(confGet('DIR_STREBER') . 'render/render_form.inc.php');
00088
00089 if($msg= confGet('LOGIN_MESSAGE')) {
00090 echo
00091 "<div class=text>"
00092 .$msg
00093 ."</div>";
00094 }
00095
00096 $block=new PageBlock(array(
00097 'title' =>__('please login'),
00098 'id' =>'functions',
00099 'reduced_header' => true,
00100 ));
00101 $block->render_blockStart();
00102
00103
00104 $form=new PageForm();
00105 $form->add(new Form_Input('login_name', __('Nickname', 'label in login form'),'') );
00106 $form->add(new Form_Password('login_password', __('Password','label in login form'),'') );
00107 #$form->form_options[]="<span class=option><input name='login_forgot_password' class='checker' type=checkbox>".__("I forgot my password")."</span>";
00108 $form->form_options[]=$PH->getLink('loginForgotPassword');
00109
00110 if(confGet('ANONYMOUS_USER')) {
00111 $form->form_options[]= $PH->getLink('home',__("Continue anonymously"));
00112 }
00113
00114 ### add probably go-values as hidden fields ###
00115 $go_after= NULL;
00116 if( confGet('USE_MOD_REWRITE')
00117 && get('go') == 'globalView'
00118 ) {
00119 $go_after= get('id');
00120 if($go_after =='login') {
00121 $go_after= '';
00122 }
00123
00124 }
00125 else {
00126 $go_after= get('go');
00127 }
00128
00129 if( $go_after != ""
00130 && $go_after != 'logout'
00131 && $go_after != 'loginForm'
00132 && $go_after != 'loginFormSubmit'
00133 ) {
00134 $form->add(new Form_Hiddenfield('go_after','', $go_after));
00135 foreach($g_valid_login_params as $var) {
00136 if($value= get($var)) {
00137 $form->add(new Form_Hiddenfield($var,'', $value));
00138 }
00139 }
00140 }
00141
00142 ### guess user's local time with javascript ###
00143 echo "<input type=hidden id=user_timeoffset name=user_timeoffset>";
00144 echo '<script type="text/javascript">
00145 var now = new Date();document.getElementById("user_timeoffset").value= (now.getHours() + ":" + now.getMinutes() +":"+ now.getSeconds());
00146 </script>';
00147
00148 echo ($form);
00149 $block->render_blockEnd();
00150
00151 $PH->go_submit='loginFormSubmit';
00152 }
00153 echo (new PageContentClose);
00154 echo (new PageHtmlEnd);
00155
00156 }
00157
00163 global $g_time_offset; # in seconds
00164 $g_time_offset = 0;
00165
00172 function loginFormSubmit()
00173 {
00174 global $PH;
00175 global $auth;
00176 global $g_languages;
00177 global $g_valid_login_params;
00178
00179 ### get formdata ####
00180 $name= get('login_name');
00181
00182 if(!is_null(get('login_password'))) {
00183 $password_md5= md5(get('login_password'));
00184 }
00185
00186 else if(!is_null(get('login_password_md5'))) { # required for auto login
00187 $password_md5= get('login_password_md5');
00188 }
00189
00193 if(
00194 $auth->tryLoginUser($name,$password_md5)
00195
00196 ) {
00197 $PH->messages= array();
00198
00199 $auth->storeUserCookie();
00200
00201 if(isset($g_languages[$auth->cur_user->language])) {
00202 setLang($auth->cur_user->language);
00203 }
00204
00205 ### display taskView ####
00206 $projects=$auth->cur_user->getProjects();
00207
00208 ### if go-parameter was present before logging in
00209 if($go_after= get('go_after')) {
00210 $params=array();
00211 foreach($g_valid_login_params as $var) {
00212 if(get($var)) {
00213 $params[$var]= get($var);
00214 }
00215 }
00216 log_message("show(go_after=".get('go_after').")", LOG_MESSAGE_DEBUG);
00217 $PH->show(get('go_after'),$params);
00218 }
00219 ### if user has only one project go there ###
00220 else if(count($projects) == 1) {
00221 $PH->messages[]= sprintf(confGet('MESSAGE_WELCOME_ONEPROJECT'), asHtml($auth->cur_user->name),asHtml($projects[0]->name));
00222 $PH->show('projView',array('prj'=>$projects[0]->id));
00223 }
00224 else {
00225 $PH->messages[]=confGet('MESSAGE_WELCOME_HOME');
00226 $PH->show('home',array());
00227 }
00228 }
00229 else {
00230 log_message("invalid login. Show loginForm again", LOG_MESSAGE_DEBUG);
00231 $PH->messages[]=__('invalid login','message when login failed');
00232 $PH->show('loginForm');
00233 }
00234 }
00235
00236
00240 function logout(){
00241 global $PH;
00242 global $auth;
00243
00244 ### kill cookie ###
00245 $auth->removeUserCookie();
00246 $PH->cur_page_md5=NULL;
00247
00253 if($cur_user= Person::getById($auth->cur_user->id)) {
00254 $cur_user->cookie_string= $auth->cur_user->calcCookieString();
00255 $cur_user->last_logout= getGMTString();
00256 $cur_user->update();
00257 }
00258
00259
00260
00261 ### go to login-page ####
00262 $PH->messages[]="Logged out";
00263 $PH->show('loginForm');
00264 #header("location:index.php");
00265
00266
00267 if($auth->cur_user) {
00268 $nickname= $auth->cur_user->nickname;
00269 }
00270 else {
00271 $nickname= '_nobody_';
00272 }
00273 log_message("'".$nickname."' logged out from:". $_SERVER["REMOTE_ADDR"], LOG_MESSAGE_LOGOUT);
00274
00278 {
00279 require_once(confGet('DIR_STREBER') . 'std/mail.inc.php');
00280 $n= new Notifier();
00281 $n->sendNotifications();
00282 }
00283 }
00284
00285
00286
00287
00288
00292 function loginForgotPassword()
00293 {
00294 global $PH;
00295 global $auth;
00296 global $g_valid_login_params;
00297
00298 if(isset($auth->cur_user)) {
00299 $auth->cur_user=NULL;
00300 }
00301
00302
00303 ### set up page and write header ###
00304 {
00305 $page= new Page(array('autofocus_field'=>'login_name'));
00306 global $g_tabs_login;
00307 $page->tabs= $g_tabs_login;
00308
00309 $page->cur_tab='login';
00310 $page->type="";
00311 $page->title=__('Password reminder','Page title');
00312
00313 echo(new PageHeader);
00314 }
00315 echo (new PageContentOpen);
00316
00317 ### write form ###
00318 {
00319 require_once(confGet('DIR_STREBER') . 'render/render_form.inc.php');
00320
00321
00322 $block=new PageBlock(array(
00323 'title' =>__('Please enter your nickname'),
00324 'id' =>'functions',
00325 'reduced_header' => true,
00326 ));
00327 $block->render_blockStart();
00328
00329
00330 $form=new PageForm();
00331 $form->button_cancel=true;
00332
00333 $msg= __("We will then sent you an E-mail with a link to adjust your password."). " ";
00334 if($mail= confGet('EMAIL_ADMINISTRATOR')) {
00335 $msg.= sprintf(__("If you do not know your nickname, please contact your administrator: %s.") , "<a href='mailto:$mail'>$mail</a>");
00336 }
00337
00338 $form->add(new Form_Text($msg));
00339
00340 $form->add(new Form_Input('login_name', __('Nickname', 'label in login form'),'') );
00341 #$form->form_options[]="<span class=option><input name='login_forgot_password' class='checker' type=checkbox>".__("I forgot my password")."</span>";
00342
00343
00344 echo ($form);
00345 $block->render_blockEnd();
00346
00347 $PH->go_submit='loginForgotPasswordSubmit';
00348 }
00349 echo (new PageContentClose);
00350 echo (new PageHtmlEnd);
00351 }
00352
00353
00354
00355
00359 function loginForgotPasswordSubmit()
00360 {
00361 global $PH;
00362 global $auth;
00363
00364
00365 ### cancel? ###
00366 if(get('form_do_cancel')) {
00367 if(!$PH->showFromPage()) {
00368 $PH->show('loginForm');
00369 }
00370 exit();
00371 }
00372
00373 if(!$name= get('login_name')) {
00374 $PH->messages[]=__('If you remember your name, please enter it and try again.');
00375 $PH->show('loginForgotPassword');
00376 exit();
00377 }
00378 else {
00379 if($person=Person::getByNickname(get('login_name'))) {
00380 if($person->can_login) {
00381
00382 if($person->office_email || $person->personal_email) {
00383
00384
00385 require_once(confGet('DIR_STREBER') . 'std/mail.inc.php');
00386 $n= new Notifier();
00387 $n->sendPasswordReminder($person);
00388
00389 $person->settings |= USER_SETTING_NOTIFICATIONS;
00390 $person->settings |= USER_SETTING_SEND_ACTIVATION;
00391
00392 }
00393 }
00394 }
00395
00396 $PH->messages[]=__('A notification mail has been sent.');
00397 $PH->show('loginForm');
00398 exit();
00399 }
00400 }
00401
00402
00403
00404
00408 function activateAccount()
00409 {
00410 global $auth;
00411 global $PH;
00412 $auth->removeUserCookie();
00413 if($tuid= get('tuid')) {
00414 $tuid = asKey($tuid); # clean string
00415 if($user= $auth->setCurUserByIdentifier($tuid)) {
00416 $auth->storeUserCookie();
00417 $PH->messages[]=sprintf(__("Welcome %s. Please adjust your profile and insert a good password to activate your account."), asHtml($user->name));
00418 global $g_person_fields;
00419 $PH->show('personEdit',array('person'=>$user->id));
00420 exit();
00421 }
00422 }
00423 $PH->messages[]=__("Sorry, but this activation code is no longer valid. If you already have an account, you could enter your name and use the <b>forgot password link</b> below.");
00424 $PH->show('loginForm');
00425 }
00426
00427
00428
00429
00430
00434 function helpLicense()
00435 {
00436 global $PH;
00437
00438 ### create from handle ###
00439
00440 ### set up page and write header ####
00441 {
00442 $page= new Page(array());
00443
00444 global $g_tabs_login;
00445 $page->tabs=$g_tabs_login;
00446
00447 $page->cur_tab='license';
00448 $page->type="";
00449 $page->title=__('License','page title');
00450
00451 echo(new PageHeader);
00452 }
00453 echo (new PageContentOpen);
00454
00455 require_once(confGet('DIR_STREBER') . 'lang/license.html');
00456
00457 echo (new PageContentClose);
00458 echo (new PageHtmlEnd);
00459 }
00460
00461 ?>