pages/company.inc.php

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 
00007 require_once(confGet('DIR_STREBER') . 'db/class_task.inc.php');
00008 require_once(confGet('DIR_STREBER') . 'db/class_project.inc.php');
00009 require_once(confGet('DIR_STREBER') . 'db/class_company.inc.php');
00010 require_once(confGet('DIR_STREBER') . 'render/render_list.inc.php');
00011 require_once(confGet('DIR_STREBER') . 'lists/list_companies.inc.php');
00012 
00013 
00021 function companyList() {
00022     global $PH;
00023     global $auth;
00024 
00025 
00026 
00027     ### create from handle ###
00028     $PH->defineFromHandle();
00029 
00030     ### set up page and write header ####
00031     {
00032         $page= new Page();
00033         $page->cur_tab='companies';
00034         $page->title=__("Companies");
00035         if(!($auth->cur_user->user_rights & RIGHT_VIEWALL)) {
00036             $page->title_minor=sprintf(__("related projects of %s"), $page->title_minor=$auth->cur_user->name);
00037         }
00038         else {
00039             $page->title_minor=__("admin view");
00040         }
00041         $page->type=__("List");
00042 
00043         /*$page->crumbs[]= new NaviCrumb(array(
00044             'target_id'     => 'companyList',
00045         ));*/
00046         $page->options=build_companyList_options();
00047 
00048 
00049         ### page functions ###
00050         if($auth->cur_user->user_rights & RIGHT_COMPANY_CREATE) {
00051 
00052             ### page functions ###
00053             $page->add_function(new PageFunctionGroup(array(
00054                 'name'      => __('new:')
00055             )));
00056             $page->add_function(new PageFunction(array(
00057                 'target'=>'companyNew',
00058                 'name'=>__('Company'),
00059                 'params'=>array('company_category'=>CCATEGORY_UNDEFINED),
00060             )));
00061         }
00062 
00063         ### render title ###
00064         echo(new PageHeader);
00065     }
00066     echo (new PageContentOpen);
00067 
00068     #--- list projects --------------------------------------------------------
00069     {
00070 
00071 
00072         $list= new ListBlock_companies();
00073 
00074         ### may user create companies? ###
00075         if($auth->cur_user->user_rights & RIGHT_COMPANY_CREATE) {
00076             $list->no_items_html=$PH->getLink('companyNew','',array('person'=>$auth->cur_user->id));
00077         }
00078         else {
00079             $list->no_items_html=__("no companies");
00080         }
00081 
00082 
00083         $order_str= get("sort_".$PH->cur_page->id."_".$list->id);
00084 
00085         $order_str= str_replace(",",", ", $order_str);
00086         $companies=Company::getAll(array('order_str'=>$order_str));
00087 
00088         $list->title= $page->title;
00089         $list->render_list(&$companies);
00090 
00091         ### Link to start cvs export ###
00092         $format = get('format');
00093         if($format == FORMAT_HTML || $format == ''){
00094             #echo "<div class=description>" . $PH->getLink('companyList', __('Export as CSV'),array('format'=>FORMAT_CSV)) . "</div>";
00095             echo $PH->getCSVLink();
00096         }
00097     }
00098 
00099     echo(new PageContentClose);
00100     echo(new PageHtmlEnd);
00101 
00102 }
00103 
00109 function companyListClient()
00110 {
00111     global $PH;
00112     global $auth;
00113 
00114     ### create from handle ###
00115     $PH->defineFromHandle();
00116 
00117     ### set up page and write header ####
00118     {
00119         $page= new Page();
00120         $page->cur_tab='companies';
00121         $page->title=__("Clients");
00122         if(!($auth->cur_user->user_rights & RIGHT_VIEWALL)) {
00123             $page->title_minor=sprintf(__("related companies of %s"), $page->title_minor=$auth->cur_user->name);
00124         }
00125         else {
00126             $page->title_minor=__("admin view");
00127         }
00128         $page->type=__("List", "page type");
00129 
00130         $page->options=build_companyList_options();
00131 
00132         ### page functions ###
00133         if($auth->cur_user->user_rights & RIGHT_COMPANY_CREATE) {
00134 
00135             ### page functions ###
00136             $page->add_function(new PageFunctionGroup(array(
00137                 'name'      => __('new:')
00138             )));
00139             $page->add_function(new PageFunction(array(
00140                 'target'=>'companyNew',
00141                 'name'=>__('Company'),
00142                 'params'=>array('company_category'=>CCATEGORY_CLIENT),
00143             )));
00144         }
00145 
00146 
00147         ### render title ###
00148         echo(new PageHeader);
00149     }
00150     echo (new PageContentOpen);
00151 
00152     #--- list projects --------------------------------------------------------
00153     {
00154         $list= new ListBlock_companies();
00155 
00156         ### may user create companies? ###
00157         if($auth->cur_user->user_rights & RIGHT_COMPANY_CREATE) {
00158             $list->no_items_html=$PH->getLink('companyNew','',array('person'=>$auth->cur_user->id));
00159         }
00160         else {
00161             $list->no_items_html=__("no companies");
00162         }
00163 
00164 
00165         $order_str= get("sort_".$PH->cur_page->id."_".$list->id);
00166 
00167         $order_str= str_replace(",",", ", $order_str);
00168 
00169         $comcat = CCATEGORY_CLIENT;
00170 
00171         $companies=Company::getAll(array(
00172                             'order_str'=>$order_str,
00173                             'has_id'=>NULL,
00174                             'search'=>NULL,
00175                             'comcat'=>$comcat
00176                             ));
00177 
00178         $list->title= $page->title;
00179         $list->render_list(&$companies);
00180 
00181         ## Link to start cvs export ##
00182         $format = get('format');
00183         if($format == FORMAT_HTML || $format == ''){
00184             #echo "<div class=description>" . $PH->getLink('companyListClient', __('Export as CSV'),array('format'=>FORMAT_CSV)) . "</div>";
00185             echo $PH->getCSVLink();
00186         }
00187     }
00188 
00189     echo(new PageContentClose);
00190     echo(new PageHtmlEnd);
00191 
00192 }
00193 
00198 function companyListProsClient()
00199 {
00200     global $PH;
00201     global $auth;
00202 
00203     ### create from handle ###
00204     $PH->defineFromHandle();
00205 
00206     ### set up page and write header ####
00207     {
00208         $page= new Page();
00209         $page->cur_tab='companies';
00210         $page->title=__("Prospective Clients");
00211         if(!($auth->cur_user->user_rights & RIGHT_VIEWALL)) {
00212             $page->title_minor=sprintf(__("related companies of %s"), $page->title_minor=$auth->cur_user->name);
00213         }
00214         else {
00215             $page->title_minor=__("admin view");
00216         }
00217         $page->type=__("List", "page type");
00218 
00219         $page->options=build_companyList_options();
00220 
00221 
00222         ### page functions ###
00223         if($auth->cur_user->user_rights & RIGHT_COMPANY_CREATE) {
00224 
00225             ### page functions ###
00226             $page->add_function(new PageFunctionGroup(array(
00227                 'name'      => __('new:')
00228             )));
00229             $page->add_function(new PageFunction(array(
00230                 'target'=>'companyNew',
00231                 'name'=>__('Company'),
00232                 'params'=>array('company_category'=>CCATEGORY_PROSCLIENT),
00233             )));
00234         }
00235 
00236         ### render title ###
00237         echo(new PageHeader);
00238     }
00239     echo (new PageContentOpen);
00240 
00241     #--- list projects --------------------------------------------------------
00242     {
00243         $list= new ListBlock_companies();
00244 
00245         ### may user create companies? ###
00246         if($auth->cur_user->user_rights & RIGHT_COMPANY_CREATE) {
00247             $list->no_items_html=$PH->getLink('companyNew','',array('person'=>$auth->cur_user->id));
00248         }
00249         else {
00250             $list->no_items_html=__("no companies");
00251         }
00252 
00253         $order_str= get("sort_".$PH->cur_page->id."_".$list->id);
00254 
00255         $order_str= str_replace(",",", ", $order_str);
00256 
00257         $comcat = CCATEGORY_PROSCLIENT;
00258 
00259         $companies=Company::getAll(array(
00260                             'order_str'=>$order_str,
00261                             'has_id'=>NULL,
00262                             'search'=>NULL,
00263                             'comcat'=>$comcat
00264                             ));
00265 
00266         $list->title= $page->title;
00267         $list->render_list(&$companies);
00268 
00269         ## Link to start cvs export ##
00270         $format = get('format');
00271         if($format == FORMAT_HTML|| $format == ''){
00272             #echo "<div class=description>" . $PH->getLink('companyListProsClient', __('Export as CSV'),array('format'=>FORMAT_CSV)) . "</div>";
00273             echo $PH->getCSVLink();
00274         }
00275     }
00276 
00277     echo(new PageContentClose);
00278     echo(new PageHtmlEnd);
00279 }
00280 
00285 function companyListSupplier()
00286 {
00287     global $PH;
00288     global $auth;
00289 
00290     ### create from handle ###
00291     $PH->defineFromHandle();
00292 
00293     ### set up page and write header ####
00294     {
00295         $page= new Page();
00296         $page->cur_tab='companies';
00297         $page->title=__("Suppliers");
00298         if(!($auth->cur_user->user_rights & RIGHT_VIEWALL)) {
00299             $page->title_minor=sprintf(__("related companies of %s"), $page->title_minor=$auth->cur_user->name);
00300         }
00301         else {
00302             $page->title_minor=__("admin view");
00303         }
00304         $page->type=__("List", "page type");
00305 
00306         $page->options=build_companyList_options();
00307 
00308         ### page functions ###
00309         if($auth->cur_user->user_rights & RIGHT_COMPANY_CREATE) {
00310 
00311             ### page functions ###
00312             $page->add_function(new PageFunctionGroup(array(
00313                 'name'      => __('new:')
00314             )));
00315             $page->add_function(new PageFunction(array(
00316                 'target'=>'companyNew',
00317                 'name'=>__('Company'),
00318                 'params'=>array('company_category'=>CCATEGORY_SUPPLIER),
00319             )));
00320         }
00321 
00322         ### render title ###
00323         echo(new PageHeader);
00324     }
00325     echo (new PageContentOpen);
00326 
00327     #--- list projects --------------------------------------------------------
00328     {
00329         $list= new ListBlock_companies();
00330 
00331         ### may user create companies? ###
00332         if($auth->cur_user->user_rights & RIGHT_COMPANY_CREATE) {
00333             $list->no_items_html=$PH->getLink('companyNew','',array('person'=>$auth->cur_user->id));
00334         }
00335         else {
00336             $list->no_items_html=__("no companies");
00337         }
00338 
00339         $order_str= get("sort_".$PH->cur_page->id."_".$list->id);
00340 
00341         $order_str= str_replace(",",", ", $order_str);
00342 
00343         $comcat = CCATEGORY_SUPPLIER;
00344 
00345         $companies=Company::getAll(array(
00346                             'order_str'=>$order_str,
00347                             'has_id'=>NULL,
00348                             'search'=>NULL,
00349                             'comcat'=>$comcat
00350                             ));
00351 
00352         $list->title= $page->title;
00353         $list->render_list(&$companies);
00354 
00355         ## Link to start cvs export ##
00356         $format = get('format');
00357         if($format == FORMAT_HTML|| $format == ''){
00358             #echo "<div class=description>" . $PH->getLink('companyListSupplier', __('Export as CSV'),array('format'=>FORMAT_CSV)) . "</div>";
00359             echo $PH->getCSVLink();
00360         }
00361     }
00362 
00363     echo(new PageContentClose);
00364     echo(new PageHtmlEnd);
00365 
00366 }
00367 
00373 function companyListPartner()
00374 {
00375     global $PH;
00376     global $auth;
00377 
00378     ### create from handle ###
00379     $PH->defineFromHandle();
00380 
00381     ### set up page and write header ####
00382     {
00383         $page= new Page();
00384         $page->cur_tab='companies';
00385         $page->title=__("Partners");
00386         if(!($auth->cur_user->user_rights & RIGHT_VIEWALL)) {
00387             $page->title_minor=sprintf(__("related companies of %s"), $page->title_minor=$auth->cur_user->name);
00388         }
00389         else {
00390             $page->title_minor=__("admin view");
00391         }
00392         $page->type=__("List", "page type");
00393 
00394         $page->options=build_companyList_options();
00395 
00396         ### page functions ###
00397         if($auth->cur_user->user_rights & RIGHT_COMPANY_CREATE) {
00398 
00399             ### page functions ###
00400             $page->add_function(new PageFunctionGroup(array(
00401                 'name'      => __('new:')
00402             )));
00403             $page->add_function(new PageFunction(array(
00404                 'target'=>'companyNew',
00405                 'name'=>__('Company'),
00406                 'params'=>array('company_category'=>CCATEGORY_PARTNER),
00407             )));
00408         }
00409 
00410         ### render title ###
00411         echo(new PageHeader);
00412     }
00413     echo (new PageContentOpen);
00414 
00415     #--- list projects --------------------------------------------------------
00416     {
00417         $list= new ListBlock_companies();
00418 
00419         ### may user create companies? ###
00420         if($auth->cur_user->user_rights & RIGHT_COMPANY_CREATE) {
00421             $list->no_items_html=$PH->getLink('companyNew','',array('person'=>$auth->cur_user->id));
00422         }
00423         else {
00424             $list->no_items_html=__("no companies");
00425         }
00426 
00427         $order_str= get("sort_".$PH->cur_page->id."_".$list->id);
00428 
00429         $order_str= str_replace(",",", ", $order_str);
00430 
00431         $comcat = CCATEGORY_PARTNER;
00432 
00433         $companies=Company::getAll(array(
00434                             'order_str'=>$order_str,
00435                             'has_id'=>NULL,
00436                             'search'=>NULL,
00437                             'comcat'=>$comcat
00438                             ));
00439 
00440         $list->title= $page->title;
00441         $list->render_list(&$companies);
00442 
00443         ## Link to start cvs export ##
00444         $format = get('format');
00445         if($format == FORMAT_HTML || $format == ''){
00446             #echo "<div class=description>" . $PH->getLink('companyListPartner', __('Export as CSV'),array('format'=>FORMAT_CSV)) . "</div>";
00447             echo $PH->getCSVLink();
00448         }
00449     }
00450 
00451     echo(new PageContentClose);
00452     echo(new PageHtmlEnd);
00453 }
00454 
00460 function companyView()
00461 {
00462 
00463     global $PH;
00464     global $auth;
00465     require_once(confGet('DIR_STREBER') . 'render/render_wiki.inc.php');
00466 
00467     ### get current company ###
00468     $id=getOnePassedId('company','companies_*');
00469     $company= Company::getVisibleById($id);
00470     if(!$company) {
00471         $PH->abortWarning("invalid company-id");
00472         return;
00473     }
00474 
00475     ## is viewed by user ##
00476     $company->nowViewedByUser();
00477 
00478     $company->validateView();
00479 
00480     ### create from handle ###
00481     $PH->defineFromHandle(array('company'=>$company->id));
00482 
00483 
00484 
00485     ### set up page ####
00486     {
00487         $page= new Page();
00488         $page->cur_tab='companies';
00489         $page->title=$company->name;
00490         $page->title_minor=__("Overview");
00491         $page->type=__("Company");
00492 
00493 
00494         ### breadcrumbs  ###
00495         $page->crumbs= build_company_crumbs($company);
00496 
00497 
00498         ### page functions ###
00499         $page->add_function(new PageFunctionGroup(array(
00500             'name'      => __('edit:')
00501         )));
00502 
00503         $page->add_function(new PageFunction(array(
00504             'target'    =>'companyEdit',
00505             'params'    =>array('company'=>$company->id),
00506             'icon'      =>'edit',
00507             'tooltip'   =>__('Edit this company'),
00508             'name'      =>__('Company'),
00509         )));
00510         
00511         $item = ItemPerson::getAll(array('person'=>$auth->cur_user->id,'item'=>$company->id));
00512         if((!$item) || ($item[0]->is_bookmark == 0)){
00513             $page->add_function(new PageFunction(array(
00514                 'target'    =>'itemsAsBookmark',
00515                 'params'    =>array('company'=>$company->id),
00516                 'tooltip'   =>__('Mark this company as bookmark'),
00517                 'name'      =>__('Bookmark'),
00518             )));
00519         }
00520         else{
00521             $page->add_function(new PageFunction(array(
00522                 'target'    =>'itemsRemoveBookmark',
00523                 'params'    =>array('company'=>$company->id),
00524                 'tooltip'   =>__('Remove this bookmark'),
00525                 'name'      =>__('Remove Bookmark'),
00526             )));
00527         } 
00528         
00529         if($company->state == 1) {
00530             $page->add_function(new PageFunction(array(
00531                 'target'=>'companyDelete',
00532                 'params'=>array('company'=>$company->id),
00533                 'icon'=>'delete',
00534                 'tooltip'=>__('Delete this company'),
00535                 'name'=>__('Delete')
00536             )));
00537         }
00538 
00539         $page->add_function(new PageFunctionGroup(array(
00540             'name'      => __('new:')
00541         )));
00542 
00543         $page->add_function(new PageFunction(array(
00544             'target'    =>'personNew',
00545             'params'    =>array('company'=>$company->id),
00546             'icon'      =>'new',
00547             'tooltip'   =>__('Create new person for this company'),
00548             'name'      =>__('Person'),
00549         )));
00550         $page->add_function(new PageFunction(array(
00551             'target'    =>'projNew',
00552             'params'    =>array('company'=>$company->id),
00553             'icon'      =>'new',
00554             'tooltip'   =>__('Create new project for this company'),
00555             'name'      =>__('Project'),
00556         )));
00557         $page->add_function(new PageFunction(array(
00558             'target'    =>'companyLinkPersons',
00559             'params'    =>array('company'=>$company->id),
00560             'icon'      =>'add',
00561             'tooltip'   =>__('Add existing persons to this company'),
00562             'name'      =>__('Persons'),
00563         )));
00564 
00565 
00566 
00567 
00568         ### render title ###
00569         echo(new PageHeader);
00570     }
00571     echo (new PageContentOpen_Columns);
00572 
00573 
00574     #--- write info block ------------
00575     {
00576         $block=new PageBlock(array('title'=>__('Summary'), 'id'=>'summary'));
00577         $block->render_blockStart();
00578         echo "<div class=text>";
00579 
00580         if($company->comments) {
00581             echo wiki2html($company->comments);
00582         }
00583         if($company->street) {
00584             echo '<p><label>'. __('Adress') . ':</label>' . asHtml($company->street) .'</p>';
00585         }
00586         if($company->zipcode) {
00587             echo '<p><label></label>' . asHtml($company->zipcode). '</p>';
00588         }
00589         if($company->phone) {
00590             echo '<p><label>'. __('Phone') . ':</label>' . asHtml($company->phone) .'</p>';
00591         }
00592         if($company->fax) {
00593             echo '<p><label>'. __('Fax') . ':</label>' . asHtml($company->fax) .'</p>';
00594         }
00595 
00596 
00597         if($company->homepage) {
00598             echo '<p><label>'. __('Web') . ':</label>'.url2linkExtern($company->homepage).'</p>';
00599         }
00600         if($company->intranet) {
00601             echo '<p><label>'. __('Intra') . ':</label>'.url2linkExtern($company->intranet).'</p>';
00602         }
00603         if($company->email) {
00604             echo '<p><label>'. __('Mail') . ':</label>'.url2linkMail($company->email).'</p>';
00605         }
00606 
00607         echo "</div>";
00608 
00609         $block->render_blockEnd();
00610     }
00611 
00612     #--- list persons -------------------------------
00613     {
00614         require_once(confGet('DIR_STREBER') . 'pages/person.inc.php');
00615         $list= new ListBlock_persons();
00616 
00617         $persons= $company->getPersons();
00618 
00619         $list->title= __('related Persons');
00620         $list->id="related_persons";
00621         unset($list->columns['tagline']);
00622         unset($list->columns['nickname']);
00623         unset($list->columns['profile']);
00624         unset($list->columns['projects']);
00625 
00626         unset($list->columns['personal_phone']);
00627         unset($list->columns['office_phone']);
00628         unset($list->columns['companies']);
00629         unset($list->columns['changes']);
00630         unset($list->columns['last_login']);
00631 
00632         unset($list->functions['personDelete']);
00633         unset($list->functions['personEditRights']);
00634 
00640         $list->add_function(new ListFunction(array(
00641             'target'=>$PH->getPage('companyLinkPersons')->id,
00642             #'params'    =>array('company'=>$company->id),
00643             'name'  =>__('Link Persons'),
00644             'id'    =>'companyLinkPersons',
00645             'icon'  =>'add',
00646         )));
00647         $list->add_function(new ListFunction(array(
00648             'target'=>$PH->getPage('companyPersonsDelete')->id,
00649             'name'  =>__('Remove person from company'),
00650             'id'    =>'companyPersonsDelete',
00651             'icon'  =>'sub',
00652             'context_menu'=>'submit',
00653         )));
00654 
00655         if($auth->cur_user->user_rights & RIGHT_COMPANY_EDIT) {
00656             $list->no_items_html=
00657                 $PH->getLink('companyLinkPersons',__('link existing Person'),array('company'=>$company->id))
00658                 ." ". __("or")." "
00659                 .$PH->getLink('personNew',__('create new'),array('company'=>$company->id));
00660         }
00661         else {
00662             $list->no_items_html=__("no persons related");
00663         }
00664 
00665         #$list->render_list(&$persons);
00666         $list->print_automatic(&$persons);
00667     }
00668 
00669 
00670     echo(new PageContentNextCol);
00671 
00672 
00673     #--- list open projects------------------------------------------------------------
00674 
00675     {
00676         require_once(confGet('DIR_STREBER') . 'lists/list_projects.inc.php');
00677         $order_by= get('sort_'.$PH->cur_page->id."_projects");
00678 
00679         $list= new ListBlock_projects();
00680 
00681         $list->title=__("Active projects");
00682         $list->id="active_projects";
00683         $list->groupings= NULL;
00684         $list->block_functions = NULL;
00685 
00686         unset($list->columns['company']);
00687 
00688         unset($list->functions['projNew']);
00689         unset($list->functions['projDelete']);
00690         $list->query_options['status_min']= STATUS_UPCOMING;
00691         $list->query_options['status_max']= STATUS_OPEN;
00692         $list->query_options['company']= $company->id;
00693 
00694 
00695         if($auth->cur_user->user_rights & RIGHT_PROJECT_CREATE) {
00696             $list->no_items_html=$PH->getLink('projNew',__('Create new project'),array('company'=>$company->id))." ".
00697             __(" Hint: for already existing projects please edit those and adjust company-setting.");
00698         }
00699         else {
00700             $list->no_items_html=__("no projects yet");
00701         }
00702 
00703         $list->print_automatic();
00704 
00705     }
00706 
00707 
00708     #--- list closed projects------------------------------------------------------------
00709     {
00710         $list= new ListBlock_projects();
00711         $list->groupings= NULL;
00712         $list->block_functions = NULL;
00713 
00714         $list->title=__("Closed projects");
00715         $list->id="closed_projects";
00716         unset($list->columns['company']);
00717 
00718         unset($list->functions['projNew']);
00719         unset($list->functions['projDelete']);
00720         $list->query_options['status_min']= STATUS_BLOCKED;
00721         $list->query_options['status_max']= STATUS_CLOSED;
00722         $list->query_options['company']= $company->id;
00723 
00724         $list->print_automatic();
00725     }
00726 
00727     ### add company-id ###
00728     # note: some pageFunctions like personNew can use this for automatical linking
00729     echo "<input type=hidden name=company value='$company->id'>";
00730 
00731 
00732     echo (new PageContentClose);
00733     echo (new PageHtmlEnd);
00734 }
00735 
00736 
00743 function companyNew() {
00744     global $PH;
00745 
00746     $name=get('new_name')
00747         ? get('new_name')
00748         :__("New Company");
00749 
00750 
00751     if(get('company_category')) {
00752         $category= get('company_category');
00753     }
00754     else {
00755         $category= CCATEGORY_UNDEFINED;
00756     }
00757 
00758     ### build new object ###
00759     $newCompany= new Company(array(
00760         'id'=>0,
00761         'name'=>$name,
00762         'category'=>$category,
00763         )
00764     );
00765     $PH->show('companyEdit',array('company'=>$newCompany->id),$newCompany);
00766 }
00767 
00768 
00773 function companyEdit($company=NULL)
00774 {
00775     global $PH;
00776     global $auth;
00777 
00778     ### use object or get from database ###
00779     if(!$company) {
00780         $id= getOnePassedId('company','companies_*');   # WARNS if multiple; ABORTS if no id found
00781         $company= Company::getEditableById($id);
00782         if(!$company) {
00783             $PH->abortWarning("ERROR: could not get Company");
00784             return;
00785         }
00786     }
00787 
00788     ### set up page and write header ####
00789     {
00790         $page= new Page(array('use_jscalendar'=>true, 'autofocus_field'=>'company_name'));
00791         $page->cur_tab='companies';
00792         $page->type=__("Edit Company");
00793         $page->title=$company->name;
00794 
00795         $page->crumbs= build_company_crumbs($company);
00796         $page->options[]= new NaviOption(array(
00797             'target_id'     => 'companyEdit',
00798         ));
00799 
00800         echo(new PageHeader);
00801     }
00802     echo (new PageContentOpen);
00803 
00804     $block=new PageBlock(array(
00805         'id'    =>'edit',
00806         'reduced_header' => true,
00807     ));
00808     $block->render_blockStart();
00809 
00810     ### write form #####
00811     {
00812         global $g_ccategory_names;
00813         require_once(confGet('DIR_STREBER') . 'render/render_form.inc.php');
00814 
00815         $form=new PageForm();
00816         $form->button_cancel=true;
00817 
00818         foreach($company->fields as $field) {
00819             $form->add($field->getFormElement(&$company));
00820         }
00821 
00822         ### dropdown menu for company category ###
00823         if($c= get('comcat')){
00824             $comcat = $c;
00825         }
00826         else {
00827             $comcat = $company->category;
00828         }
00829         $form->add(new Form_Dropdown('ccategory',  __('Category','form label'),array_flip($g_ccategory_names), $comcat));
00830 
00831         ### create another  ###
00832         if($auth->cur_user->user_rights & RIGHT_COMPANY_CREATE && $company->id == 0) {
00833             $checked= get('create_another')
00834             ? 'checked'
00835             : '';
00836 
00837             $form->form_options[]="<span class=option><input id='create_another' name='create_another' class='checker' type=checkbox $checked><label for='create_another'>" . __("Create another company after submit") . "</label></span>";     ;
00838         }
00839 
00840 
00841         echo ($form);
00842 
00843         $PH->go_submit='companyEditSubmit';
00844 
00845         ### pass person-id? ###
00846         if($p = get('person')) {
00847             echo "<input type='hidden' name='person' value='$p'>";
00848         }
00849 
00850         echo "<input type=hidden name='company' value='$company->id'>";
00851     }
00852     $block->render_blockEnd();
00853 
00854     echo (new PageContentClose);
00855     echo (new PageHtmlEnd);
00856 
00857 }
00858 
00864 function companyEditSubmit()
00865 {
00866     global $PH;
00867     global $auth;
00868 
00869     ### cancel ###
00870     if(get('form_do_cancel')) {
00871         if(!$PH->showFromPage()) {
00872             $PH->show('home',array());
00873         }
00874         exit();
00875     }
00876 
00877     ### get company ####
00878     $id= getOnePassedId('company');
00879 
00880     ### temporary object ###
00881     if($id == 0) {
00882         $company=new Company(array());
00883     }
00884     ### get from db ###
00885     else {
00886         $company= Company::getEditableById($id);
00887         if(!$company) {
00888             $PH->abortWarning("Could not get company");
00889             return;
00890         }
00891     }
00892 
00893     $company->validateEditRequestTime();
00894 
00895     ### company category ###
00896     $ccategory = get('ccategory');
00897     if($ccategory != NULL)
00898     {
00899         $company->category = $ccategory;
00900     }
00901 
00902     # retrieve all possible values from post-data
00903     # NOTE:
00904     # - this could be an security-issue.
00905     # - TODO: as some kind of form-edit-behaviour to field-definition
00906     foreach($company->fields as $f) {
00907         $name=$f->name;
00908         $f->parseForm(&$company);
00909     }
00910 
00911     ### write to db ###
00912     if($company->id == 0) {
00913         if($company->insert()){
00914             ### link to a company ###
00915             if($p_id = get('person')) {
00916                 require_once(confGet('DIR_STREBER') . 'db/class_person.inc.php');
00917 
00918                 if($p = Person::getVisibleById($p_id)) {
00919                     require_once(confGet('DIR_STREBER') . 'db/class_employment.inc.php');
00920                     $e = new Employment(array(
00921                         'id'=>0,
00922                         'person'=>$p->id,
00923                         'company'=>$company->id
00924                     ));
00925                     $e->insert();
00926                 }
00927             }
00928 
00929         }
00930 
00931         ### show 'create another' -form
00932         if(get('create_another')) {
00933             $PH->show('companyNew',array());
00934             exit();
00935         }
00936     }
00937     else {
00938         $company->update();
00939     }
00940 
00941     ### notify on change ###
00942     $company->nowChangedByUser();
00943 
00944     ### display taskView ####
00945     if(!$PH->showFromPage()) {
00946         $PH->show('home',array());
00947     }
00948 }
00949 
00955 function companyLinkPersons() {
00956     global $PH;
00957 
00958     $id= getOnePassedId('company','companies_*');   # WARNS if multiple; ABORTS if no id found
00959     $company= Company::getEditableById($id);
00960     if(!$company) {
00961         $PH->abortWarning("ERROR: could not get Company");
00962         return;
00963     }
00964 
00965     ### set up page and write header ####
00966     {
00967         $page= new Page(array('use_jscalendar'=>true, 'autofocus_field'=>'company_name'));
00968         $page->cur_tab='companies';
00969         $page->type=__("Edit Company");
00970         $page->title=sprintf(__("Edit %s"),$company->name);
00971         $page->title_minor=__("Add persons employed or related");
00972 
00973 
00974         $page->crumbs= build_company_crumbs($company);
00975         $page->options[]= new NaviOption(array(
00976             'target_id'     => 'companyLinkPersons',
00977         ));
00978 
00979         echo(new PageHeader);
00980     }
00981     echo (new PageContentOpen);
00982 
00983     ### write form #####
00984     {
00985         require_once(confGet('DIR_STREBER') . 'pages/person.inc.php');
00986         require_once(confGet('DIR_STREBER') . 'render/render_form.inc.php');
00987         $persons= Person::getPersons();
00988         $list= new ListBlock_persons();
00989         $list->show_functions=false;
00990         $list->show_icons=false;
00991 
00992 
00993         $list->render_list(&$persons);
00994 
00995         $PH->go_submit='companyLinkPersonsSubmit';
00996         echo "<input type=hidden name='company' value='$company->id'>";
00997         echo "<input class=button2 type=submit>";
00998 
00999     }
01000     echo (new PageContentClose);
01001     echo (new PageHtmlEnd);
01002 
01003 }
01004 
01005 
01006 
01007 
01013 function companyLinkPersonsSubmit()
01014 {
01015     global $PH;
01016     require_once(confGet('DIR_STREBER') . 'db/class_person.inc.php');
01017 
01018     $id= getOnePassedId('company','companies_*');
01019     $company= Company::getEditableById($id);
01020     if(!$company) {
01021         $PH->abortWarning("Could not get object...");
01022     }
01023 
01024     $person_ids= getPassedIds('person','persons*');
01025     if(!$person_ids) {
01026         $PH->abortWarning(__("No persons selected..."));
01027     }
01028 
01029     $employments= $company->getEmployments();
01030 
01031     foreach($person_ids as $pid) {
01032         if(!$person= Person::getEditableById($pid)) {
01033             $PH->abortWarning("Could not access person by id");
01034         }
01035 
01036         #### person already employed? ###
01037         $already_in=false;
01038         foreach($employments as $e) {
01039             if($e->person == $person->id) {
01040                 $already_in= true;
01041                 break;
01042             }
01043         }
01044         if(!$already_in) {
01045             $e_new= new Employment(array(
01046                 'id'=>0,
01047                 'person'=>$person->id,
01048                 'company'=>$company->id,
01049             ));
01050             $e_new->insert();
01051         }
01052         else {
01053             new FeedbackMessage(__("Person already related to company"));
01054         }
01055     }
01056     ### display taskView ####
01057     if(!$PH->showFromPage()) {
01058         $PH->show('companyView',array('company'=>$company->id));
01059     }
01060 }
01061 
01067 function companyPersonsDelete()
01068 {
01069     global $PH;
01070 
01071     $id= getOnePassedId('company','companies_*');
01072     $company= Company::getEditableById($id);
01073     if(!$company) {
01074         $PH->abortWarning("Could not get object...");
01075     }
01076 
01077     $person_ids= getPassedIds('person','persons*');
01078     if(!$person_ids) {
01079         $PH->abortWarning(__("No persons selected..."));
01080     }
01081 
01082     $employments= $company->getEmployments();
01083 
01084     $counter = 0;
01085     $errors = 0;
01086     foreach($person_ids as $pid) {
01087         if(!$person= Person::getEditableById($pid)) {
01088             $PH->abortWarning("Could not access person by id");
01089         }
01090 
01091         $assigned_to=false;
01092         foreach($employments as $e) {
01093             if($e->person == $person->id) {
01094                 $assigned_to= true;
01095                 $e_id = $e->id;
01096 
01097                 if($assigned_to){
01098                     $e_remove = Employment::getEditableById($e_id);
01099                     if(!$e_remove) {
01100                          $PH->abortWarning("Could not access employment by id");
01101                     }
01102                     else {
01103                         if($e_remove->delete()) {
01104                             $counter++;
01105                         }
01106                         else {
01107                             $errors++;
01108                         }
01109                     }
01110                 }
01111                 else {
01112                     $PH->abortWarning("Contact person isn't related to this company");
01113                 }
01114             }
01115         }
01116     }
01117 
01118     if($errors) {
01119         new FeedbackWarning(sprintf(__("Failed to remove %s contact person(s)"),$errors));
01120     }
01121     else {
01122         new FeedbackMessage(sprintf(__("Removed %s contact person(s)"), $counter));
01123     }
01124 
01125     if(!$PH->showFromPage()) {
01126         $PH->show('companyView',array('company'=>$company->id));
01127     }
01128 }
01129 
01135 function companyDelete()
01136 {
01137     global $PH;
01138 
01139     ### get company ####
01140     $ids= getPassedIds('company','companies_*');
01141 
01142     if(!$ids) {
01143         $PH->abortWarning(__("Select some companies to delete"));
01144         return;
01145     }
01146 
01147     $counter=0;
01148     $errors=0;
01149     foreach($ids as $id) {
01150         $c= Company::getEditableById($id);
01151         if(!$c) {
01152             $PH->abortWarning("Invalid company-id!");
01153             continue;
01154         }
01155         if($c->delete()) {
01156             $counter++;
01157         }
01158         else {
01159             $errors++;
01160         }
01161     }
01162     if($errors) {
01163         new FeedbackWarning(sprintf(__("Failed to delete %s companies"), $errors));
01164     }
01165     else {
01166         new FeedbackMessage(sprintf(__("Moved %s companies to trash"),$counter));
01167     }
01168 
01169     ### display companyList ####
01170     $PH->show('companyList');
01171 }
01172 
01175 ?>

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