svn.diff

webmyster, 12/16/2012 07:22 AM

Download (14.7 KB)

View differences:

inc/useremail.class.php (working copy)
119 119
   }
120 120

  
121 121

  
122
   static function getJSHTMLFieldsToAddForItem($html_field, $nb_item_var) {
123
      return "<input title=\'".__s('Default email')."\' type=\'radio\' name=\'_default_email\'" .
124
             " value=\'-'+$nb_item_var+'\'>&nbsp;".
125
             "<input type=\'text\' size=\'30\' ". "name=\'".$html_field."[-'+$nb_item_var+']\'>";
126
   }
127

  
128

  
129
   function showChildForItemForm($canedit, $input_name) {
130

  
131
      if ($this->isNewID($this->getID())) {
132
         $value = '';
133
      } else {
134
         $value = $this->fields['email'];
135
      }
136

  
137
      echo "<input title='".__s('Default email')."' type='radio' name='_default_email'
138
                value='".$this->getID()."'";
139
      if (!$canedit) {
140
         echo " disabled";
141
      }
142
      if ($this->fields['is_default']) {
143
         echo " checked";
144
      }
145
      echo ">&nbsp;";
146
      if (!$canedit || $this->fields['is_dynamic']) {
147
         echo "<input type='hidden' name='$input_name' value='$value'>";
148
         printf(__('%1$s %2$s'), $value, "<span class='b'>(". __('D').")</span>");
149
      } else {
150
         echo "<input type='text' size=30 name='$input_name' value='$value' >";
151
      }
152
   }
153

  
154

  
122 155
   /**
123 156
    * Show emails of a user
124 157
    *
......
127 160
    * @return nothing
128 161
   **/
129 162
   static function showForUser(User $user) {
130
      global $DB, $CFG_GLPI;
131 163

  
132 164
      $users_id = $user->getID();
133 165

  
......
137 169
      }
138 170
      $canedit = ($user->can($users_id,"w") || ($users_id == Session::getLoginUserID()));
139 171

  
140
      // To be sure not to load bad datas from glpi_useremails table
141
      if ($users_id == 0) {
142
         $users_id = -99;
143
      }
172
      parent::showFieldsForItemForm($user, '_useremails', $canedit);
144 173

  
145
      $count = 0;
146

  
147
      // Display emails
148
      foreach ($DB->request("glpi_useremails", array('users_id' => $users_id,
149
                                                     'ORDER'    => 'email')) as $data) {
150
         if ($count) {
151
            echo '<br>';
152
         }
153
         $count++;
154

  
155
         echo "<input title='".__s('Default email')."' type='radio' name='_default_email'
156
                value='".$data['id']."'".
157
                ($canedit?' ':' disabled').($data['is_default'] ? ' checked' : ' ').">&nbsp;";
158
         if (!$canedit || $data['is_dynamic']) {
159
            echo "<input type='hidden' name='_useremails[".$data['id']."]' value='".$data['email']."'>";
160
            printf(__('%1$s %2$s'), $data['email'], "<span class='b'>(". __('D').")</span>");
161
         } else {
162
            echo "<input type='text' size=30 name='_useremails[".$data['id']."]'
163
                   value='".$data['email']."' >";
164
         }
165

  
166
         if (!NotificationMail::isUserAddressValid($data['email'])) {
167
            echo "<span class='red'>&nbsp;".__('Invalid email address')."</span>";
168
         }
169
      }
170

  
171
      if ($canedit) {
172
         echo "<div id='emailadd$users_id'>";
173
         // No email display field
174
         if ($count == 0) {
175
            echo "<input type='text' size='40' name='_useremails[-100]' value=''>";
176
         }
177
         echo "</div>";
178
      }
179

  
180 174
   }
181 175

  
182 176

  
......
184 178
    * @param $user
185 179
   **/
186 180
   static function showAddEmailButton(User $user) {
187
      global $CFG_GLPI;
188 181

  
189 182
      $users_id = $user->getID();
190 183
      if (!$user->can($users_id,'r') && ($users_id != Session::getLoginUserID())) {
......
192 185
      }
193 186
      $canedit = ($user->can($users_id,"w") || ($users_id == Session::getLoginUserID()));
194 187

  
195
      if ($canedit) {
188
      parent::showAddButtonForChildItem($user, '_useremails');
196 189

  
197
         echo "&nbsp;<script type='text/javascript'>var nbemails=1; </script>";
198
         echo "<span id='addemailbutton'><img title=\"".__s('Add')."\" alt=\"".__s('Add').
199
               "\" onClick=\"var row = Ext.get('emailadd$users_id');
200
                             row.createChild('<input type=\'text\' size=\'40\' ".
201
                                               "name=\'_useremails[-'+nbemails+']\'><br>');
202
                             nbemails++;\"
203
               class='pointer' src='".$CFG_GLPI["root_doc"]."/pics/add_dropdown.png'></span>";
204
      }
190
      return;
205 191
   }
206 192

  
207 193

  
inc/networkname.class.php (working copy)
195 195
                           'displaywith' => array('view')));
196 196
      echo "</td>\n</tr>\n";
197 197

  
198
      $address = new IPAddress();
199 198
      echo "<tr class='tab_bg_1'>";
200
      echo "<td>".$address->getTypeName(2);
199
      echo "<td>".IPAddress::getTypeName(2);
201 200
      IPAddress::showAddButtonForChildItem($this, '_ipaddresses');
202 201
      echo "</td>";
203 202
      echo "<td>";
204
      $address->showFieldsForItemForm($this, '_ipaddresses', 'name');
203
      IPAddress::showFieldsForItemForm($this, '_ipaddresses');
205 204
      echo "</td>\n";
206 205

  
207 206
      echo "<td>".__('Comments')."</td>";
......
474 473

  
475 474
      echo "</tr><tr class='tab_bg_1'>\n";
476 475

  
477
      $address = new IPAddress();
478
      echo "<td>".$address->getTypeName(2);
479
      $address->showAddButtonForChildItem($name, 'NetworkName__ipaddresses');
476
      echo "<td>".IPAddress::getTypeName(2);
477
      IPAddress::showAddButtonForChildItem($name, 'NetworkName__ipaddresses');
480 478
      echo "</td>";
481 479
      echo "<td>";
482
      $address->showFieldsForItemForm($name, 'NetworkName__ipaddresses', 'name');
480
      IPAddress::showFieldsForItemForm($name, 'NetworkName__ipaddresses');
483 481
      echo "</td>";
484 482

  
485 483
      echo "<td>".IPNetwork::getTypeName(2)."&nbsp;";
inc/user.class.php (working copy)
536 536
         $useremail = new UserEmail();
537 537
         foreach ($this->input['_useremails'] as $id => $email) {
538 538
            $email = trim($email);
539
            $useremail->add(array('email'    => $email,
540
                                  'users_id' => $this->getID()));
539
            $email_input = array('email'    => $email,
540
                                 'users_id' => $this->getID());
541
            if ((isset($this->input['_default_email']))
542
                && ($this->input['_default_email'] == $id)) {
543
               $email_input['is_default'] = 1;
544
            } else {
545
               $email_input['is_default'] = 0;
546
            }
547
            $useremail->add($email_input);
541 548
         }
542 549
      }
543 550

  
......
706 713
               }
707 714

  
708 715
            } else { // New email
709
               $useremail->add(array('email'    => $email,
710
                                     'users_id' => $this->getID()));
716
               $email_input = array('email'    => $email,
717
                                    'users_id' => $this->getID());
718
               if ((isset($this->input['_default_email']))
719
                   && ($this->input['_default_email'] == $id)) {
720
                  $email_input['is_default'] = 1;
721
               } else {
722
                  $email_input['is_default'] = 0;
723
               }
724
               $useremail->add($email_input);
711 725
            }
712 726
         }
713 727
      }
......
1590 1604
      echo "</tr>";
1591 1605

  
1592 1606
      echo "<tr class='tab_bg_1'>";
1593
      echo "<td class='top'>" . _n('Email','Emails',2);
1607
      echo "<td>" . _n('Email','Emails',2);
1594 1608
      UserEmail::showAddEmailButton($this);
1595 1609
      echo "</td><td>";
1596 1610
      UserEmail::showForUser($this);
inc/commondbchild.class.php (working copy)
531 531
   }
532 532

  
533 533

  
534
   static function getJSHTMLFieldsToAddForItem($html_field, $nb_item_var) {
535
      return "<input type=\'text\' size=\'40\' ". "name=\'".$html_field."[-'+$nb_item_var+']\'>";
536
   }
537

  
538

  
539
   function showChildForItemForm($canedit, $input_name) {
540

  
541
      if ($this->isNewID($this->getID())) {
542
         $value = '';
543
      } else {
544
         $value = $this->getName();
545
      }
546
      if ($canedit) {
547
         echo "<input type='text' size='40' name='$input_name' value='$value'>";
548
      } else {
549
         echo "<input type='hidden' name='$input_name' value='$value'>$value" ;
550
      }
551
   }
552

  
553

  
534 554
   /**
535 555
    * We can add several CommonDBChild to a given Item. In such case, we display a "+" button and
536 556
    * the fields already entered
......
539 559
    * @since version 0.84
540 560
    *
541 561
    * @todo study if we cannot use these methods for the user emails
542
    * @see showFieldsForItemForm(CommonDBTM $item, $html_field, $db_field)
562
    * @see showFieldsForItemForm(CommonDBTM $item, $html_field)
543 563
    *
544 564
    * @param $item         CommonDBTM object: the item on which to add the current CommenDBChild
545 565
    * @param $html_field   the name of the HTML field inside the Item form
546 566
    *
547 567
    * @return nothing (display only)
548 568
   **/
549
   static function showAddButtonForChildItem(CommonDBTM $item, $html_field) {
569
   static function showAddButtonForChildItem(CommonDBTM $item, $html_field, $canedit = NULL) {
550 570
      global $CFG_GLPI;
551 571

  
552 572
      $items_id = $item->getID();
553 573

  
554
      if ($item->isNewItem()) {
555
         if (!$item->canCreate()) {
556
            return false;
574
      if (is_null($canedit)) {
575
         if ($item->isNewItem()) {
576
            if (!$item->canCreate()) {
577
               return false;
578
            }
579
            $canedit = $item->canUpdate();
580
         } else {
581
            if (!$item->can($items_id,'r')) {
582
               return false;
583
            }
584

  
585
            $canedit = $item->can($items_id,"w");
557 586
         }
558
         $canedit = $item->canUpdate();
559
      } else {
560
         if (!$item->can($items_id,'r')) {
561
            return false;
562
         }
563

  
564
         $canedit = $item->can($items_id,"w");
565 587
      }
566 588

  
567 589
      $lower_name  = strtolower(get_called_class());
568 590
      $nb_item_var = 'nb'.$lower_name.'s';
569
      $div_id      = $lower_name."add$items_id";
591
      $div_id      = "add_".$lower_name."_to_".$item->getType()."_".$items_id;
570 592

  
571 593
      if ($canedit) {
572 594

  
......
574 596
         echo "<span id='add".$lower_name."button'>".
575 597
              "<img title=\"".__s('Add')."\" alt=\"". __s('Add').
576 598
                "\" onClick=\"var row = Ext.get('$div_id');
577
                             row.createChild('<input type=\'text\' size=\'40\' ".
578
                "name=\'".$html_field."[-'+$nb_item_var+']\'><br>');
599
                             row.createChild('<br>" .
600
               static::getJSHTMLFieldsToAddForItem($html_field, $nb_item_var)."');
579 601
                            $nb_item_var++;\"
580 602
               class='pointer' src='".$CFG_GLPI["root_doc"]."/pics/add_dropdown.png'></span>";
581 603
      }
......
594 616
    *
595 617
    * @param $item         CommonDBTM object the item on which to add the current CommenDBChild
596 618
    * @param $html_field                     the name of the HTML field inside the Item form
597
    * @param $db_field                       the name of the field inside the CommonDBChild table
598
    *                                        to display
599 619
    *
600 620
    * @return nothing (display only)
601 621
   **/
602
   function showFieldsForItemForm(CommonDBTM $item, $html_field, $db_field) {
622
   static function showFieldsForItemForm(CommonDBTM $item, $html_field, $canedit = NULL) {
603 623
      global $DB, $CFG_GLPI;
604 624

  
605 625
      $items_id = $item->getID();
606 626

  
607
      if ($item->isNewItem()) {
608
         if (!$item->canCreate()) {
609
            return false;
627
      if (is_null($canedit)) {
628
         if ($item->isNewItem()) {
629
            if (!$item->canCreate()) {
630
               return false;
631
            }
632
            $canedit = $item->canUpdate();
633
         } else {
634
            if (!$item->can($items_id,'r')) {
635
               return false;
636
            }
637

  
638
            $canedit = $item->can($items_id,"w");
610 639
         }
611
         $canedit = $item->canUpdate();
612
      } else {
613
         if (!$item->can($items_id,'r')) {
614
            return false;
615
         }
616

  
617
         $canedit = $item->can($items_id,"w");
618 640
      }
619 641

  
620
      $lower_name = strtolower($this->getType());
621
      $div_id     = $lower_name."add$items_id";
642
      $lower_name = strtolower(get_called_class());
643
      $div_id     = "add_".$lower_name."_to_".$item->getType()."_".$items_id;
622 644

  
623 645
     // To be sure not to load bad datas from glpi_itememails table
624 646
      if ($items_id == 0) {
625 647
         $items_id = -99;
626 648
      }
627 649

  
628
      $query = "SELECT `$db_field`, `".static::getIndexName()."`
629
                FROM `" . $this->getTable() . "`
650
      $query = "SELECT *
651
                FROM `" . static::getTable() . "`
630 652
                WHERE `".static::$items_id."` = '".$item->getID()."'";
631 653

  
632 654
      if (preg_match('/^itemtype/', static::$itemtype)) {
633 655
         $query .= " AND `itemtype` = '".$item->getType()."'";
634 656
      }
635 657

  
636
      $setDefault = $this->isField('is_default');
637 658

  
659
      $current_item = new static();
660

  
638 661
      $count = 0;
639 662
      foreach ($DB->request($query) as $data) {
640 663

  
641
         $data['is_default'] = 0;
642
         $data['is_dynamic'] = 0;
664
         $current_item->fields = $data;
643 665

  
644 666
         if ($count) {
645 667
            echo '<br>';
646 668
         }
647 669
         $count++;
648 670

  
649
         if ($setDefault) {
650
            echo "<input title='" . sprintf(__s('Default %s'), $this->getTypeName(1)) .
651
                   "' type='radio' name='_default_email' value='".$data[static::getIndexName()]."'".
652
                   ($canedit?' ':' disabled').($data['is_default'] ? ' checked' : ' ').">&nbsp;";
653
         }
671
         $current_item->showChildForItemForm($canedit, $html_field . "[" .
672
                                                      $current_item->getID() . "]");
654 673

  
655
         $input_name  = $html_field . "[" . $data[static::getIndexName()] . "]";
656
         $input_value = $data[$db_field];
657

  
658
         if (!$canedit
659
             || (isset($data['is_dynamic']) && $data['is_dynamic'])) {
660
            echo "<input type='hidden' name='$input_name' value='$input_value'>" .$input_value;
661
            //TRANS: D for Dynamic
662
            echo "<span class='b'>&nbsp;".__('(D)')."</span>";
663
         } else {
664
            echo "<input type='text' size='40' name='$input_name' value='$input_value'>";
665
         }
666

  
667
         /*
668
         if (!NotificationMail::isItemAddressValid($data['email'])) {
669
            echo "<span class='red'>&nbsp;".__('Invalid email address')."</span>";
670
         }
671
         */
672 674
      }
673 675

  
674 676
      if ($canedit) {
675 677
         echo "<div id='$div_id'>";
676 678
         // No email display field
677 679
         if ($count == 0) {
678
            echo "<input type='text' size='40' name='".$html_field."[-100]' value=''>";
680
            $current_item->getEmpty();
681
            $current_item->showChildForItemForm($canedit, $html_field . "[-100]");
679 682
         }
680 683
         echo "</div>";
681 684
      }