/** * Get code * @return string */ private function getCode() { $Code = ' <table class="fullwidth zebra-style c"> <thead> <tr class="b"> <th>' . __('Name') . '</th> <th>' . __('Abbreviation') . '</th> <th>' . Ajax::tooltip(__('Sport'), __('A type can only belong to one sport.')) . '</th> <th>' . Ajax::tooltip('Ø ' . __('HR'), __('Average heart rate (used for calculation of TRIMP)')) . '</th> <th>' . Ajax::tooltip(__('Quality?'), __('Quality sessions will be emphasized in your calendar.')) . '</th> <th>' . Ajax::tooltip(__('Race'), __('You need to set one type for running as race type.')) . '</th> <th>' . Ajax::tooltip(Icon::$CROSS_SMALL, __('A type can only be deleted if no references exist.')) . '</th> </tr> </thead> <tbody>'; $Types = DB::getInstance()->query(' SELECT ty.id, ty.name, ty.abbr, ty.sportid, ty.hr_avg, ty.quality_session, ty.accountid, ( SELECT COUNT(*) FROM `' . PREFIX . 'training` tr WHERE tr.typeid = ty.id AND `accountid`="' . SessionAccountHandler::getId() . '" ) AS tcount FROM `' . PREFIX . 'type` ty WHERE `accountid`="' . SessionAccountHandler::getId() . '" ORDER BY `id` ASC ')->fetchAll(); //TODO Change all locations where Typeid is used $Types[] = array('id' => -1, 'sportid' => -1, 'name' => '', 'abbr' => '', 'hr_avg' => 120, 'quality_session' => 0); $raceID = Configuration::General()->competitionType(); foreach ($Types as $Data) { $id = $Data['id']; if ($id == -1) { $delete = ''; } elseif ($Data['tcount'] == 0) { $delete = '<input type="checkbox" name="type[delete][' . $id . ']">'; } else { $delete = SearchLink::to('typeid', $id, '<small>(' . $Data['tcount'] . ')</small>'); } $Sports = SportFactory::AllSportsWithTypes(); $Code .= ' <tr class="' . ($id == -1 ? ' unimportant' : '') . '"> <td><input type="text" size="20" name="type[name][' . $id . ']" value="' . $Data['name'] . '"></td> <td><input type="text" size="3" name="type[abbr][' . $id . ']" value="' . $Data['abbr'] . '"></td> <td><select name="type[sportid][' . $id . ']">'; foreach ($Sports as $SData) { $Code .= '<option value="' . $SData['id'] . '"' . HTML::Selected($SData['id'] == $Data['sportid']) . '>' . $SData['name'] . '</option>'; } $Code .= '</select></td> <td> <span class="input-with-unit"> <input type="text" name="type[hr_avg][' . $id . ']" value="' . $Data['hr_avg'] . '" id="type_hr_avg_' . $id . '" class="small-size"> <label for="type_hr_avg_' . $id . '" class="input-unit">bpm</label> </span> </td> <td><input type="checkbox" name="type[quality_session][' . $id . ']"' . ($Data['quality_session'] ? ' checked' : '') . '></td> <td><input type="radio" name="racetype" value="' . $id . '"' . ($id == $raceID ? ' checked' : '') . '></td> <td>' . $delete . '</td> </tr>'; } $Code .= ' </tbody> </table>'; return $Code; }